2015-12-18 14:24:34 +00:00
< ? php
2018-03-07 18:29:48 +00:00
/**
* Class WC_Shipping_Legacy_International_Delivery file .
*
* @ package WooCommerce\Shipping
*/
2015-12-18 14:24:34 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
/**
* International Delivery - Based on the Flat Rate Shipping Method .
*
2017-07-17 10:10:52 +00:00
* This class is here for backwards compatibility for methods existing before zones existed .
2015-12-18 14:24:34 +00:00
*
* @ deprecated 2.6 . 0
2018-03-07 18:04:56 +00:00
* @ version 2.4 . 0
* @ package WooCommerce / Classes / Shipping
2015-12-18 14:24:34 +00:00
*/
class WC_Shipping_Legacy_International_Delivery extends WC_Shipping_Legacy_Flat_Rate {
/**
* Constructor .
*/
public function __construct () {
2018-03-07 18:29:48 +00:00
$this -> id = 'legacy_international_delivery' ;
$this -> method_title = __ ( 'International flat rate (legacy)' , 'woocommerce' );
/* translators: %s: Admin shipping settings URL */
2016-10-24 23:56:38 +00:00
$this -> method_description = '<strong>' . sprintf ( __ ( 'This method is deprecated in 2.6.0 and will be removed in future versions - we recommend disabling it and instead setting up a new rate within your <a href="%s">Shipping zones</a>.' , 'woocommerce' ), admin_url ( 'admin.php?page=wc-settings&tab=shipping' ) ) . '</strong>' ;
2015-12-18 14:24:34 +00:00
$this -> init ();
add_action ( 'woocommerce_update_options_shipping_' . $this -> id , array ( $this , 'process_admin_options' ) );
}
/**
* Return the name of the option in the WP DB .
2018-03-07 18:04:56 +00:00
*
2015-12-18 14:24:34 +00:00
* @ since 2.6 . 0
* @ return string
*/
public function get_option_key () {
2018-03-07 18:29:48 +00:00
return $this -> plugin_id . 'international_delivery_settings' ;
2015-12-18 14:24:34 +00:00
}
/**
* Initialise settings form fields .
*/
public function init_form_fields () {
parent :: init_form_fields ();
$this -> form_fields [ 'availability' ] = array (
2018-03-07 18:04:56 +00:00
'title' => __ ( 'Availability' , 'woocommerce' ),
'type' => 'select' ,
'class' => 'wc-enhanced-select' ,
'description' => '' ,
'default' => 'including' ,
'options' => array (
2015-12-18 14:24:34 +00:00
'including' => __ ( 'Selected countries' , 'woocommerce' ),
'excluding' => __ ( 'Excluding selected countries' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
),
2015-12-18 14:24:34 +00:00
);
}
/**
2018-03-07 18:29:48 +00:00
* Check if package is available .
2015-12-18 14:24:34 +00:00
*
2018-03-07 18:29:48 +00:00
* @ param array $package Package information .
2015-12-18 14:24:34 +00:00
* @ return bool
*/
public function is_available ( $package ) {
2018-03-07 18:04:56 +00:00
if ( 'no' === $this -> enabled ) {
2015-12-18 14:24:34 +00:00
return false ;
}
if ( 'including' === $this -> availability ) {
2018-03-07 18:29:48 +00:00
if ( is_array ( $this -> countries ) && ! in_array ( $package [ 'destination' ][ 'country' ], $this -> countries , true ) ) {
2015-12-18 14:24:34 +00:00
return false ;
}
} else {
2018-03-07 18:29:48 +00:00
if ( is_array ( $this -> countries ) && ( in_array ( $package [ 'destination' ][ 'country' ], $this -> countries , true ) || ! $package [ 'destination' ][ 'country' ] ) ) {
2015-12-18 14:24:34 +00:00
return false ;
}
}
2017-08-11 20:36:18 +00:00
return apply_filters ( 'woocommerce_shipping_' . $this -> id . '_is_available' , true , $package , $this );
2015-12-18 14:24:34 +00:00
}
}