2012-05-26 16:25:07 +00:00
< ? php
2018-03-07 18:30:26 +00:00
/**
* Class WC_Shipping_Local_Pickup file .
*
* @ package WooCommerce\Shipping
*/
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
*
2018-03-07 18:04:56 +00:00
* @ class WC_Shipping_Local_Pickup
* @ version 2.6 . 0
* @ package WooCommerce / Classes / Shipping
2012-08-14 22:43:48 +00:00
*/
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 .
2017-05-15 11:50:52 +00:00
*
2018-03-07 18:30:26 +00:00
* @ param int $instance_id Instance ID .
2012-08-14 22:43:48 +00:00
*/
2015-12-16 16:09:52 +00:00
public function __construct ( $instance_id = 0 ) {
2018-03-07 18:04:56 +00:00
$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 (
2015-12-16 16:09:52 +00:00
'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
2018-03-07 18:30:26 +00:00
// Define user set variables.
2018-03-07 18:04:56 +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
2018-03-07 18:30:26 +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
/**
2016-01-06 19:15:45 +00:00
* Calculate local pickup shipping .
2017-05-15 11:50:52 +00:00
*
2018-03-07 18:30:26 +00:00
* @ param array $package Package information .
2012-08-14 22:43:48 +00:00
*/
2015-12-18 17:10:58 +00:00
public function calculate_shipping ( $package = array () ) {
2018-03-07 18:04:56 +00:00
$this -> add_rate (
array (
'label' => $this -> title ,
'package' => $package ,
'cost' => $this -> cost ,
)
);
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 (
2018-03-07 18:04:56 +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' ),
2016-10-12 10:16:30 +00:00
'default' => __ ( 'Local pickup' , 'woocommerce' ),
2014-11-11 15:46:54 +00:00
'desc_tip' => true ,
2016-06-06 13:19:58 +00:00
),
'tax_status' => array (
2018-03-07 18:04:56 +00:00
'title' => __ ( 'Tax status' , 'woocommerce' ),
'type' => 'select' ,
'class' => 'wc-enhanced-select' ,
'default' => 'taxable' ,
'options' => array (
'taxable' => __ ( 'Taxable' , 'woocommerce' ),
'none' => _x ( 'None' , 'Tax status' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
),
2016-06-06 13:19:58 +00:00
),
2018-03-07 18:04:56 +00:00
'cost' => array (
'title' => __ ( 'Cost' , 'woocommerce' ),
'type' => 'text' ,
'placeholder' => '0' ,
'description' => __ ( 'Optional cost for local pickup.' , 'woocommerce' ),
'default' => '' ,
'desc_tip' => true ,
2016-08-27 01:46:45 +00:00
),
2012-05-26 16:25:07 +00:00
);
}
2014-09-20 19:44:32 +00:00
}