class-wc-shipping-local-pickup.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WC_Shipping_Local_Pickup file. |
| 4 | * |
| 5 | * @package WooCommerce\Shipping |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Local Pickup Shipping Method. |
| 14 | * |
| 15 | * A simple shipping method allowing free pickup as a shipping method. |
| 16 | * |
| 17 | * @class WC_Shipping_Local_Pickup |
| 18 | * @version 2.6.0 |
| 19 | * @package WooCommerce\Classes\Shipping |
| 20 | */ |
| 21 | class WC_Shipping_Local_Pickup extends WC_Shipping_Method { |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @param int $instance_id Instance ID. |
| 27 | */ |
| 28 | public function __construct( $instance_id = 0 ) { |
| 29 | $this->id = 'local_pickup'; |
| 30 | $this->instance_id = absint( $instance_id ); |
| 31 | $this->method_title = __( 'Local pickup', 'woocommerce' ); |
| 32 | $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' ); |
| 33 | $this->supports = array( |
| 34 | 'shipping-zones', |
| 35 | 'instance-settings', |
| 36 | 'instance-settings-modal', |
| 37 | ); |
| 38 | $this->init(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Initialize local pickup. |
| 43 | */ |
| 44 | public function init() { |
| 45 | |
| 46 | // Load the settings. |
| 47 | $this->init_form_fields(); |
| 48 | $this->init_settings(); |
| 49 | |
| 50 | // Define user set variables. |
| 51 | $this->title = $this->get_option( 'title' ); |
| 52 | $this->tax_status = $this->get_option( 'tax_status' ); |
| 53 | $this->cost = $this->get_option( 'cost' ); |
| 54 | |
| 55 | // Actions. |
| 56 | add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Calculate local pickup shipping. |
| 61 | * |
| 62 | * @param array $package Package information. |
| 63 | */ |
| 64 | public function calculate_shipping( $package = array() ) { |
| 65 | $this->add_rate( |
| 66 | array( |
| 67 | 'label' => $this->title, |
| 68 | 'package' => $package, |
| 69 | 'cost' => $this->cost, |
| 70 | ) |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Init form fields. |
| 76 | */ |
| 77 | public function init_form_fields() { |
| 78 | $this->instance_form_fields = array( |
| 79 | 'title' => array( |
| 80 | 'title' => __( 'Title', 'woocommerce' ), |
| 81 | 'type' => 'text', |
| 82 | 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), |
| 83 | 'default' => __( 'Local pickup', 'woocommerce' ), |
| 84 | 'desc_tip' => true, |
| 85 | ), |
| 86 | 'tax_status' => array( |
| 87 | 'title' => __( 'Tax status', 'woocommerce' ), |
| 88 | 'type' => 'select', |
| 89 | 'class' => 'wc-enhanced-select', |
| 90 | 'default' => 'taxable', |
| 91 | 'options' => array( |
| 92 | 'taxable' => __( 'Taxable', 'woocommerce' ), |
| 93 | 'none' => _x( 'None', 'Tax status', 'woocommerce' ), |
| 94 | ), |
| 95 | ), |
| 96 | 'cost' => array( |
| 97 | 'title' => __( 'Cost', 'woocommerce' ), |
| 98 | 'type' => 'text', |
| 99 | 'placeholder' => '0', |
| 100 | 'description' => __( 'Optional cost for local pickup.', 'woocommerce' ), |
| 101 | 'default' => '', |
| 102 | 'desc_tip' => true, |
| 103 | ), |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 |