class-wc-shipping-local-pickup.php 2.7 KB

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