2015-12-18 14:24:34 +00:00
< ? php
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
/**
* Local Delivery 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
* @ version 2.3 . 0
* @ package WooCommerce / Classes / Shipping
* @ author WooThemes
*/
class WC_Shipping_Legacy_Local_Delivery extends WC_Shipping_Local_Pickup {
/**
* Constructor .
*/
public function __construct () {
$this -> id = 'legacy_local_delivery' ;
2016-10-12 10:16:30 +00:00
$this -> method_title = __ ( 'Local delivery (legacy)' , 'woocommerce' );
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 ();
}
2016-04-28 11:36:49 +00:00
/**
* Process and redirect if disabled .
*/
public function process_admin_options () {
parent :: process_admin_options ();
2016-08-27 03:23:21 +00:00
if ( 'no' === $this -> settings [ 'enabled' ] ) {
2016-04-28 11:36:49 +00:00
wp_redirect ( admin_url ( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) );
exit ;
}
}
2016-07-11 14:56:35 +00:00
2015-12-18 14:24:34 +00:00
/**
* Return the name of the option in the WP DB .
* @ since 2.6 . 0
* @ return string
*/
public function get_option_key () {
return $this -> plugin_id . 'local_delivery' . '_settings' ;
}
/**
* init function .
*/
public function init () {
// Load the settings.
$this -> init_form_fields ();
$this -> init_settings ();
// Define user set variables
$this -> title = $this -> get_option ( 'title' );
$this -> type = $this -> get_option ( 'type' );
$this -> fee = $this -> get_option ( 'fee' );
$this -> type = $this -> get_option ( 'type' );
$this -> codes = $this -> get_option ( 'codes' );
$this -> availability = $this -> get_option ( 'availability' );
$this -> countries = $this -> get_option ( 'countries' );
add_action ( 'woocommerce_update_options_shipping_' . $this -> id , array ( $this , 'process_admin_options' ) );
}
/**
* calculate_shipping function .
*
* @ param array $package ( default : array ())
*/
public function calculate_shipping ( $package = array () ) {
$shipping_total = 0 ;
switch ( $this -> type ) {
case 'fixed' :
$shipping_total = $this -> fee ;
break ;
case 'percent' :
$shipping_total = $package [ 'contents_cost' ] * ( $this -> fee / 100 );
break ;
case 'product' :
foreach ( $package [ 'contents' ] as $item_id => $values ) {
if ( $values [ 'quantity' ] > 0 && $values [ 'data' ] -> needs_shipping () ) {
$shipping_total += $this -> fee * $values [ 'quantity' ];
2016-07-11 14:56:35 +00:00
}
2015-12-18 14:24:34 +00:00
}
break ;
}
$rate = array (
2016-04-20 14:03:10 +00:00
'id' => $this -> id ,
'label' => $this -> title ,
'cost' => $shipping_total ,
'package' => $package ,
2015-12-18 14:24:34 +00:00
);
$this -> add_rate ( $rate );
}
/**
* Init form fields .
*/
public function init_form_fields () {
$this -> form_fields = array (
'enabled' => array (
'title' => __ ( 'Enable' , 'woocommerce' ),
'type' => 'checkbox' ,
2016-01-08 12:01:01 +00:00
'label' => __ ( 'Once disabled, this legacy method will no longer be available.' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'default' => 'no' ,
2015-12-18 14:24:34 +00:00
),
'title' => array (
'title' => __ ( 'Title' , 'woocommerce' ),
'type' => 'text' ,
'description' => __ ( 'This controls the title which the user sees during checkout.' , 'woocommerce' ),
2016-10-12 10:16:30 +00:00
'default' => __ ( 'Local delivery' , 'woocommerce' ),
2015-12-18 14:24:34 +00:00
'desc_tip' => true ,
),
'type' => array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Fee type' , 'woocommerce' ),
2015-12-18 14:24:34 +00:00
'type' => 'select' ,
'class' => 'wc-enhanced-select' ,
'description' => __ ( 'How to calculate delivery charges' , 'woocommerce' ),
'default' => 'fixed' ,
'options' => array (
'fixed' => __ ( 'Fixed amount' , 'woocommerce' ),
'percent' => __ ( 'Percentage of cart total' , 'woocommerce' ),
'product' => __ ( 'Fixed amount per product' , 'woocommerce' ),
),
'desc_tip' => true ,
),
'fee' => array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Delivery fee' , 'woocommerce' ),
2015-12-18 14:24:34 +00:00
'type' => 'price' ,
'description' => __ ( 'What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.' , 'woocommerce' ),
'default' => '' ,
'desc_tip' => true ,
2016-08-27 01:46:45 +00:00
'placeholder' => wc_format_localized_price ( 0 ),
2015-12-18 14:24:34 +00:00
),
'codes' => array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Allowed ZIP/post codes' , 'woocommerce' ),
2015-12-18 14:24:34 +00:00
'type' => 'text' ,
'desc_tip' => __ ( 'What ZIP/post codes are available for local delivery?' , 'woocommerce' ),
'default' => '' ,
'description' => __ ( 'Separate codes with a comma. Accepts wildcards, e.g. <code>P*</code> will match a postcode of PE30. Also accepts a pattern, e.g. <code>NG1___</code> would match NG1 1AA but not NG10 1AA' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'placeholder' => 'e.g. 12345, 56789' ,
2015-12-18 14:24:34 +00:00
),
'availability' => array (
'title' => __ ( 'Method availability' , 'woocommerce' ),
'type' => 'select' ,
'default' => 'all' ,
'class' => 'availability wc-enhanced-select' ,
'options' => array (
'all' => __ ( 'All allowed countries' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'specific' => __ ( 'Specific Countries' , 'woocommerce' ),
),
2015-12-18 14:24:34 +00:00
),
'countries' => array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Specific countries' , 'woocommerce' ),
2015-12-18 14:24:34 +00:00
'type' => 'multiselect' ,
'class' => 'wc-enhanced-select' ,
2016-12-21 11:36:48 +00:00
'css' => 'width: 400px;' ,
2015-12-18 14:24:34 +00:00
'default' => '' ,
'options' => WC () -> countries -> get_shipping_countries (),
'custom_attributes' => array (
2016-08-27 01:46:45 +00:00
'data-placeholder' => __ ( 'Select some countries' , 'woocommerce' ),
),
),
2015-12-18 14:24:34 +00:00
);
}
}