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

107 lines
2.7 KiB
PHP
Raw Normal View History

2012-05-26 16:25:07 +00:00
<?php
/**
* Class WC_Shipping_Local_Pickup file.
*
* @package WooCommerce\Shipping
*/
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
* @version 2.6.0
2020-08-05 16:36:24 +00:00
* @package WooCommerce\Classes\Shipping
2012-08-14 22:43:48 +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.
*
* @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 ) {
$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
}
/**
* 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
// Define user set variables.
$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 local pickup shipping.
*
* @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() ) {
$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
/**
* 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(
'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',
'placeholder' => '0',
'description' => __( 'Optional cost for local pickup.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
),
2012-05-26 16:25:07 +00:00
);
}
}