2012-05-26 16:25:07 +00:00
< ? php
2014-09-20 19:44:32 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
2015-12-16 16:09:52 +00:00
exit ;
2014-09-20 19:44:32 +00:00
}
2013-02-20 17:14:46 +00:00
2012-05-26 16:25:07 +00:00
/**
2015-11-03 13:31:20 +00:00
* Local Pickup Shipping Method .
2012-08-14 22:43:48 +00:00
*
2015-11-03 13:31:20 +00:00
* A simple shipping method allowing free pickup as a shipping method .
2012-05-26 16:25:07 +00:00
*
2012-12-31 18:25:09 +00:00
* @ class WC_Shipping_Local_Pickup
2015-12-16 16:09:52 +00:00
* @ version 2.6 . 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_Local_Pickup extends WC_Shipping_Method {
2012-05-26 16:25:07 +00:00
2012-08-14 22:43:48 +00:00
/**
2015-11-03 13:31:20 +00:00
* Constructor .
2012-08-14 22:43:48 +00:00
*/
2015-12-16 16:09:52 +00:00
public function __construct ( $instance_id = 0 ) {
$this -> id = 'local_pickup' ;
$this -> instance_id = absint ( $instance_id );
$this -> method_title = __ ( 'Local Pickup' , 'woocommerce' );
$this -> method_description = __ ( 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.' , 'woocommerce' );
$this -> supports = array (
'shipping-zones' ,
2016-03-24 18:31:39 +00:00
'instance-settings' ,
'instance-settings-modal' ,
2015-12-16 16:09:52 +00:00
);
2012-05-26 16:25:07 +00:00
$this -> init ();
2012-08-14 22:43:48 +00:00
}
2013-08-12 21:09:04 +00:00
/**
2016-01-06 19:15:45 +00:00
* Initialize local pickup .
2013-08-12 21:09:04 +00:00
*/
2014-11-11 15:46:54 +00:00
public function init () {
2012-08-14 22:43:48 +00:00
2012-05-26 16:25:07 +00:00
// Load the settings.
2013-01-02 13:38:33 +00:00
$this -> init_form_fields ();
2012-05-26 16:25:07 +00:00
$this -> init_settings ();
2012-08-14 22:43:48 +00:00
2012-05-26 16:25:07 +00:00
// Define user set variables
2016-06-06 13:19:58 +00:00
$this -> title = $this -> get_option ( 'title' );
$this -> tax_status = $this -> get_option ( 'tax_status' );
$this -> cost = $this -> get_option ( 'cost' );
2012-08-14 22:43:48 +00:00
2012-10-01 09:45:07 +00:00
// Actions
2012-12-15 11:53:32 +00:00
add_action ( 'woocommerce_update_options_shipping_' . $this -> id , array ( $this , 'process_admin_options' ) );
2012-05-26 16:25:07 +00:00
}
2012-08-14 22:43:48 +00:00
/**
* calculate_shipping function .
2016-01-06 19:15:45 +00:00
* Calculate local pickup shipping .
2012-08-14 22:43:48 +00:00
*/
2015-12-18 17:10:58 +00:00
public function calculate_shipping ( $package = array () ) {
2015-12-16 16:09:52 +00:00
$this -> add_rate ( array (
2016-04-20 14:03:10 +00:00
'label' => $this -> title ,
'package' => $package ,
2016-06-06 13:19:58 +00:00
'cost' => $this -> cost ,
2015-12-16 16:09:52 +00:00
) );
2012-05-26 16:25:07 +00:00
}
2012-08-14 22:43:48 +00:00
/**
2016-01-06 19:15:45 +00:00
* Init form fields .
2012-08-14 22:43:48 +00:00
*/
2014-11-11 15:46:54 +00:00
public function init_form_fields () {
2015-12-16 16:09:52 +00:00
$this -> instance_form_fields = array (
2012-05-26 16:25:07 +00:00
'title' => array (
2014-11-11 15:46:54 +00:00
'title' => __ ( 'Title' , 'woocommerce' ),
'type' => 'text' ,
'description' => __ ( 'This controls the title which the user sees during checkout.' , 'woocommerce' ),
'default' => __ ( 'Local Pickup' , 'woocommerce' ),
'desc_tip' => true ,
2016-06-06 13:19:58 +00:00
),
'tax_status' => array (
'title' => __ ( 'Tax Status' , 'woocommerce' ),
'type' => 'select' ,
'class' => 'wc-enhanced-select' ,
'default' => 'taxable' ,
'options' => array (
'taxable' => __ ( 'Taxable' , 'woocommerce' ),
2016-06-23 15:32:24 +00:00
'none' => _x ( 'None' , 'Tax status' , 'woocommerce' )
)
2016-06-06 13:19:58 +00:00
),
'cost' => array (
'title' => __ ( 'Cost' , 'woocommerce' ),
2016-06-23 15:32:24 +00:00
'type' => 'text' ,
2016-06-06 13:19:58 +00:00
'placeholder' => '0' ,
'description' => __ ( 'Optional cost for local pickup.' , 'woocommerce' ),
'default' => '' ,
2016-06-23 15:32:24 +00:00
'desc_tip' => true
2013-09-03 15:26:02 +00:00
)
2012-05-26 16:25:07 +00:00
);
}
2014-09-20 19:44:32 +00:00
}