woocommerce/includes/shipping/local-pickup/class-wc-shipping-local-pic...

97 lines
2.6 KiB
PHP
Raw Normal View History

2012-05-26 16:25:07 +00:00
<?php
if ( ! defined( 'ABSPATH' ) ) {
2015-12-16 16:09:52 +00:00
exit;
}
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
*
* @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
*/
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
}
/**
* Initialize local pickup.
*/
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
// Actions
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.
* 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
/**
* Init form fields.
2012-08-14 22:43:48 +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(
'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' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' )
)
2016-06-06 13:19:58 +00:00
),
'cost' => array(
'title' => __( 'Cost', 'woocommerce' ),
'type' => 'text',
2016-06-06 13:19:58 +00:00
'placeholder' => '0',
'description' => __( 'Optional cost for local pickup.', 'woocommerce' ),
'default' => '',
'desc_tip' => true
)
2012-05-26 16:25:07 +00:00
);
}
}