woocommerce/classes/shipping/class-wc-international-deli...

167 lines
4.9 KiB
PHP
Raw Normal View History

2012-01-31 18:13:32 +00:00
<?php
/**
* 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.
*
* @class WC_International_Delivery
2012-08-14 22:43:48 +00:00
* @version 1.6.4
* @package WooCommerce/Classes/Shipping
* @author WooThemes
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2012-01-31 18:13:32 +00:00
class WC_International_Delivery extends WC_Flat_Rate {
2012-08-14 22:43:48 +00:00
var $id = 'international_delivery';
2012-08-14 22:43:48 +00:00
/**
* __construct function.
*
* @access public
* @return void
*/
function __construct() {
$this->id = 'international_delivery';
2012-10-16 09:45:33 +00:00
$this->method_title = __( 'International Delivery', 'woocommerce' );
2012-01-31 18:13:32 +00:00
$this->flat_rate_option = 'woocommerce_international_delivery_flat_rates';
2012-10-16 09:45:33 +00:00
$this->admin_page_heading = __( 'International Delivery', 'woocommerce' );
$this->admin_page_description = __( 'International delivery based on flat rate shipping.', 'woocommerce' );
2012-05-05 13:32:24 +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'));
$this->init();
2012-08-14 22:43:48 +00:00
}
2012-01-31 18:13:32 +00:00
2012-08-14 22:43:48 +00:00
/**
2012-01-31 18:13:32 +00:00
* Initialise Gateway Settings Form Fields
2012-08-14 22:43:48 +00:00
*
* @access public
* @return void
2012-01-31 18:13:32 +00:00
*/
function init_form_fields() {
global $woocommerce;
2012-08-14 22:43:48 +00:00
2012-01-31 18:13:32 +00:00
$this->form_fields = array(
'enabled' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this shipping method', 'woocommerce' ),
2012-01-31 19:25:50 +00:00
'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' ),
2012-01-31 18:13:32 +00:00
'default' => __( 'International Delivery', 'woocommerce' )
),
2012-02-01 10:58:40 +00:00
'availability' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Availability', 'woocommerce' ),
'type' => 'select',
'description' => '',
2012-02-01 10:58:40 +00:00
'default' => 'including',
'options' => array(
2012-10-16 09:45:33 +00:00
'including' => __( 'Selected countries', 'woocommerce' ),
'excluding' => __( 'Excluding selected countries', 'woocommerce' ),
2012-02-01 10:58:40 +00:00
)
),
'countries' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Countries', 'woocommerce' ),
'type' => 'multiselect',
2012-01-31 18:13:32 +00:00
'class' => 'chosen_select',
'css' => 'width: 450px;',
'default' => '',
'options' => $woocommerce->countries->countries
),
'type' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Calculation Type', 'woocommerce' ),
'type' => 'select',
'description' => '',
2012-01-31 18:13:32 +00:00
'default' => 'order',
'options' => array(
2012-10-16 09:45:33 +00:00
'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' )
2012-01-31 18:13:32 +00:00
)
),
'tax_status' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Tax Status', 'woocommerce' ),
'type' => 'select',
'description' => '',
2012-01-31 18:13:32 +00:00
'default' => 'taxable',
'options' => array(
2012-10-16 09:45:33 +00:00
'taxable' => __( 'Taxable', 'woocommerce' ),
'none' => __( 'None', 'woocommerce' )
2012-01-31 18:13:32 +00:00
)
),
'cost' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Default Cost', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
2012-10-16 09:45:33 +00:00
'description' => __( 'Cost excluding tax. Enter an amount, e.g. 2.50.', 'woocommerce' ),
2012-01-31 18:13:32 +00:00
'default' => ''
2012-08-14 22:43:48 +00:00
),
2012-01-31 18:13:32 +00:00
'fee' => array(
2012-08-14 22:43:48 +00:00
'title' => __( 'Default 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' ),
2012-01-31 18:13:32 +00:00
'default' => ''
),
);
2012-08-14 22:43:48 +00:00
}
2012-01-31 18:13:32 +00:00
2012-08-14 22:43:48 +00:00
/**
* is_available function.
*
* @access public
* @param mixed $package
* @return bool
2012-01-31 18:13:32 +00:00
*/
2012-04-13 11:35:14 +00:00
function is_available( $package ) {
2012-01-31 18:13:32 +00:00
global $woocommerce;
2012-08-14 22:43:48 +00:00
2012-01-31 18:13:32 +00:00
if ($this->enabled=="no") return false;
2012-08-14 22:43:48 +00:00
2012-02-01 10:58:40 +00:00
if ($this->availability=='including') :
2012-08-14 22:43:48 +00:00
2012-02-01 10:58:40 +00:00
if (is_array($this->countries)) :
2012-04-13 11:35:14 +00:00
if ( ! in_array( $package['destination']['country'], $this->countries) ) return false;
2012-02-01 10:58:40 +00:00
endif;
2012-08-14 22:43:48 +00:00
2012-02-01 10:58:40 +00:00
else :
2012-08-14 22:43:48 +00:00
2012-02-01 10:58:40 +00:00
if (is_array($this->countries)) :
2012-04-13 11:35:14 +00:00
if ( in_array( $package['destination']['country'], $this->countries) ) return false;
2012-02-01 10:58:40 +00:00
endif;
2012-08-14 22:43:48 +00:00
2012-01-31 18:13:32 +00:00
endif;
2012-08-14 22:43:48 +00:00
2012-01-31 18:13:32 +00:00
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true );
2012-08-14 22:43:48 +00:00
}
2012-01-31 18:13:32 +00:00
}
2012-08-14 22:43:48 +00:00
/**
* add_international_delivery_method function.
*
2012-08-15 18:15:06 +00:00
* @package WooCommerce/Classes/Shipping
2012-08-14 22:43:48 +00:00
* @access public
* @param array $methods
* @return array
*/
2012-01-31 18:13:32 +00:00
function add_international_delivery_method( $methods ) {
2012-08-14 22:43:48 +00:00
$methods[] = 'WC_International_Delivery';
return $methods;
2012-01-31 18:13:32 +00:00
}
2012-08-14 22:43:48 +00:00
add_filter('woocommerce_shipping_methods', 'add_international_delivery_method' );