2012-01-31 18:13:32 +00:00
|
|
|
<?php
|
2013-02-20 17:14:46 +00:00
|
|
|
|
2014-09-20 19:44:32 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
2013-02-20 17:14:46 +00:00
|
|
|
|
2014-12-16 11:43:05 +00:00
|
|
|
if ( ! class_exists( 'WC_Shipping_International_Delivery' ) ) :
|
2012-01-31 18:13:32 +00:00
|
|
|
/**
|
|
|
|
* International Shipping Method based on Flat Rate shipping
|
2012-08-14 22:43:48 +00:00
|
|
|
*
|
2012-01-31 18:13:32 +00:00
|
|
|
* A simple shipping method for a flat fee per item or per order.
|
|
|
|
*
|
2012-12-31 18:25:09 +00:00
|
|
|
* @class WC_Shipping_International_Delivery
|
2014-12-16 11:43:05 +00:00
|
|
|
* @version 2.3.0
|
2012-08-14 22:43:48 +00:00
|
|
|
* @package WooCommerce/Classes/Shipping
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
2012-12-31 18:25:09 +00:00
|
|
|
class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-12-16 11:43:05 +00:00
|
|
|
public $id = 'international_delivery';
|
2012-02-06 11:16:06 +00:00
|
|
|
|
2012-08-14 22:43:48 +00:00
|
|
|
/**
|
|
|
|
* __construct function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-04-07 09:07:13 +00:00
|
|
|
public function __construct() {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
$this->id = 'international_delivery';
|
|
|
|
$this->flat_rate_option = 'woocommerce_international_delivery_flat_rates';
|
|
|
|
$this->method_title = __( 'International Delivery', 'woocommerce' );
|
|
|
|
$this->method_description = __( 'International delivery based on flat rate shipping.', 'woocommerce' );
|
2012-04-13 11:16:24 +00:00
|
|
|
|
2012-12-15 11:53:32 +00:00
|
|
|
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
|
|
|
|
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_flat_rates' ) );
|
2012-04-13 11:16:24 +00:00
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
$this->init();
|
|
|
|
}
|
2012-01-31 18:13:32 +00:00
|
|
|
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
/**
|
|
|
|
* Initialise Gateway Settings Form Fields
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-04-07 09:07:13 +00:00
|
|
|
public function init_form_fields() {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
$this->form_fields = array(
|
2012-01-31 18:13:32 +00:00
|
|
|
'enabled' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Enable/Disable', 'woocommerce' ),
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'label' => __( 'Enable this shipping method', 'woocommerce' ),
|
|
|
|
'default' => 'no'
|
2012-08-14 22:43:48 +00:00
|
|
|
),
|
2012-01-31 18:13:32 +00:00
|
|
|
'title' => array(
|
2012-08-14 22:43:48 +00:00
|
|
|
'title' => __( 'Method Title', 'woocommerce' ),
|
|
|
|
'type' => 'text',
|
|
|
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
2013-01-18 12:10:19 +00:00
|
|
|
'default' => __( 'International Delivery', 'woocommerce' ),
|
2013-08-12 21:09:04 +00:00
|
|
|
'desc_tip' => true,
|
2012-01-31 18:13:32 +00:00
|
|
|
),
|
2012-02-01 10:58:40 +00:00
|
|
|
'availability' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Availability', 'woocommerce' ),
|
|
|
|
'type' => 'select',
|
2015-01-12 17:45:47 +00:00
|
|
|
'class' => 'wc-enhanced-select',
|
2013-08-12 21:09:04 +00:00
|
|
|
'description' => '',
|
|
|
|
'default' => 'including',
|
|
|
|
'options' => array(
|
|
|
|
'including' => __( 'Selected countries', 'woocommerce' ),
|
|
|
|
'excluding' => __( 'Excluding selected countries', 'woocommerce' ),
|
2012-02-01 10:58:40 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'countries' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Countries', 'woocommerce' ),
|
|
|
|
'type' => 'multiselect',
|
2015-01-12 16:29:01 +00:00
|
|
|
'class' => 'wc-enhanced-select',
|
2012-01-31 18:13:32 +00:00
|
|
|
'css' => 'width: 450px;',
|
2013-08-12 21:09:04 +00:00
|
|
|
'default' => '',
|
2013-11-25 14:01:32 +00:00
|
|
|
'options' => WC()->countries->get_shipping_countries(),
|
2013-10-11 14:27:04 +00:00
|
|
|
'custom_attributes' => array(
|
2013-10-11 14:30:10 +00:00
|
|
|
'data-placeholder' => __( 'Select some countries', 'woocommerce' )
|
2013-10-11 14:27:04 +00:00
|
|
|
)
|
2012-01-31 18:13:32 +00:00
|
|
|
),
|
|
|
|
'tax_status' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Tax Status', 'woocommerce' ),
|
|
|
|
'type' => 'select',
|
2015-01-12 17:45:47 +00:00
|
|
|
'class' => 'wc-enhanced-select',
|
2013-08-12 21:09:04 +00:00
|
|
|
'default' => 'taxable',
|
2012-01-31 18:13:32 +00:00
|
|
|
'options' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'taxable' => __( 'Taxable', 'woocommerce' ),
|
2014-03-03 14:47:19 +00:00
|
|
|
'none' => _x( 'None', 'Tax status', 'woocommerce' )
|
2012-01-31 18:13:32 +00:00
|
|
|
)
|
|
|
|
),
|
2013-03-13 15:43:45 +00:00
|
|
|
'type' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Cost Added...', 'woocommerce' ),
|
|
|
|
'type' => 'select',
|
2015-01-12 17:45:47 +00:00
|
|
|
'class' => 'wc-enhanced-select',
|
2013-08-12 21:09:04 +00:00
|
|
|
'default' => 'order',
|
|
|
|
'options' => array(
|
|
|
|
'order' => __( 'Per Order - charge shipping for the entire order as a whole', 'woocommerce' ),
|
|
|
|
'item' => __( 'Per Item - charge shipping for each item individually', 'woocommerce' ),
|
|
|
|
'class' => __( 'Per Class - charge shipping for each shipping class in an order', 'woocommerce' ),
|
2013-03-13 15:43:45 +00:00
|
|
|
),
|
|
|
|
),
|
2012-01-31 18:13:32 +00:00
|
|
|
'cost' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Cost', 'woocommerce' ),
|
2013-11-12 17:43:30 +00:00
|
|
|
'type' => 'price',
|
|
|
|
'placeholder' => wc_format_localized_price( 0 ),
|
2013-12-04 22:20:30 +00:00
|
|
|
'description' => __( 'Cost excluding tax. Enter an amount, e.g. 2.50. Default is 0', 'woocommerce' ),
|
2013-08-12 21:09:04 +00:00
|
|
|
'default' => '',
|
2013-11-12 17:43:30 +00:00
|
|
|
'desc_tip' => true
|
2012-08-14 22:43:48 +00:00
|
|
|
),
|
2012-01-31 18:13:32 +00:00
|
|
|
'fee' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Handling Fee', 'woocommerce' ),
|
|
|
|
'type' => 'text',
|
2012-10-16 09:45:33 +00:00
|
|
|
'description' => __( 'Fee excluding tax. Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce' ),
|
2013-01-18 12:10:19 +00:00
|
|
|
'default' => '',
|
2013-08-12 21:09:04 +00:00
|
|
|
'desc_tip' => true,
|
2014-04-07 09:07:13 +00:00
|
|
|
'placeholder' => __( 'N/A', 'woocommerce' )
|
2012-01-31 18:13:32 +00:00
|
|
|
),
|
2013-02-18 16:41:32 +00:00
|
|
|
'minimum_fee' => array(
|
2013-08-12 21:09:04 +00:00
|
|
|
'title' => __( 'Minimum Handling Fee', 'woocommerce' ),
|
2013-11-12 17:43:30 +00:00
|
|
|
'type' => 'decimal',
|
2013-02-18 16:41:32 +00:00
|
|
|
'description' => __( 'Enter a minimum fee amount. Fee\'s less than this will be increased. Leave blank to disable.', 'woocommerce' ),
|
|
|
|
'default' => '',
|
2013-08-12 21:09:04 +00:00
|
|
|
'desc_tip' => true,
|
2014-04-07 09:07:13 +00:00
|
|
|
'placeholder' => __( 'N/A', 'woocommerce' )
|
2013-02-18 16:41:32 +00:00
|
|
|
),
|
2012-01-31 18:13:32 +00:00
|
|
|
);
|
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
}
|
2012-01-31 18:13:32 +00:00
|
|
|
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2013-08-12 21:09:04 +00:00
|
|
|
/**
|
|
|
|
* is_available function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $package
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-04-07 09:07:13 +00:00
|
|
|
public function is_available( $package ) {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
if ( "no" === $this->enabled ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
if ( 'including' === $this->availability ) {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
if ( is_array( $this->countries ) && ! in_array( $package['destination']['country'], $this->countries ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
} else {
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2015-03-06 14:45:00 +00:00
|
|
|
if ( is_array( $this->countries ) && ( in_array( $package['destination']['country'], $this->countries ) || ! $package['destination']['country'] ) ) {
|
2014-04-07 09:07:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
}
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-05-06 08:34:25 +00:00
|
|
|
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true, $package );
|
2013-08-12 21:09:04 +00:00
|
|
|
}
|
2012-08-14 22:43:48 +00:00
|
|
|
|
2014-04-07 09:07:13 +00:00
|
|
|
/**
|
|
|
|
* calculate_shipping function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $package (default: array())
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function calculate_shipping( $package = array() ) {
|
|
|
|
$this->rates = array();
|
|
|
|
|
|
|
|
if ( 'order' === $this->type ) {
|
|
|
|
|
|
|
|
$shipping_total = $this->order_shipping( $package );
|
|
|
|
|
|
|
|
$rate = array(
|
|
|
|
'id' => $this->id,
|
|
|
|
'label' => $this->title,
|
|
|
|
'cost' => $shipping_total ? $shipping_total : 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
} elseif ( 'class' === $this->type ) {
|
|
|
|
|
|
|
|
$shipping_total = $this->class_shipping( $package );
|
|
|
|
|
|
|
|
$rate = array(
|
|
|
|
'id' => $this->id,
|
|
|
|
'label' => $this->title,
|
|
|
|
'cost' => $shipping_total ? $shipping_total : 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
} elseif ( 'item' === $this->type ) {
|
|
|
|
|
|
|
|
$costs = $this->item_shipping( $package );
|
|
|
|
|
|
|
|
if ( ! is_array( $costs ) ) {
|
|
|
|
$costs = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$rate = array(
|
|
|
|
'id' => $this->id,
|
|
|
|
'label' => $this->title,
|
|
|
|
'cost' => $costs,
|
|
|
|
'calc_tax' => 'per_item',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $rate ) ) {
|
|
|
|
$this->add_rate( $rate );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-20 19:44:32 +00:00
|
|
|
}
|
2014-12-16 11:43:05 +00:00
|
|
|
|
2015-01-12 17:45:47 +00:00
|
|
|
endif;
|