WC_Shipping_Legacy_Local_Delivery

Local Delivery Shipping Method.

Defined (1)

The class is defined in the following location(s).

/includes/shipping/legacy-local-delivery/class-wc-shipping-legacy-local-delivery.php  
  1. class WC_Shipping_Legacy_Local_Delivery extends WC_Shipping_Local_Pickup { 
  2.  
  3. /** 
  4. * Constructor. 
  5. */ 
  6. public function __construct() { 
  7. $this->id = 'legacy_local_delivery'; 
  8. $this->method_title = __( 'Local delivery (legacy)', 'woocommerce' ); 
  9. $this->method_description = '<strong>' . sprintf( __( 'This method is deprecated in 2.6.0 and will be removed in future versions - we recommend disabling it and instead setting up a new rate within your <a href="%s">Shipping zones</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ) . '</strong>'; 
  10. $this->init(); 
  11.  
  12. /** 
  13. * Process and redirect if disabled. 
  14. */ 
  15. public function process_admin_options() { 
  16. parent::process_admin_options(); 
  17.  
  18. if ( 'no' === $this->settings['enabled'] ) { 
  19. wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) ); 
  20. exit; 
  21.  
  22. /** 
  23. * Return the name of the option in the WP DB. 
  24. * @since 2.6.0 
  25. * @return string 
  26. */ 
  27. public function get_option_key() { 
  28. return $this->plugin_id . 'local_delivery' . '_settings'; 
  29.  
  30. /** 
  31. * init function. 
  32. */ 
  33. public function init() { 
  34.  
  35. // Load the settings. 
  36. $this->init_form_fields(); 
  37. $this->init_settings(); 
  38.  
  39. // Define user set variables 
  40. $this->title = $this->get_option( 'title' ); 
  41. $this->type = $this->get_option( 'type' ); 
  42. $this->fee = $this->get_option( 'fee' ); 
  43. $this->type = $this->get_option( 'type' ); 
  44. $this->codes = $this->get_option( 'codes' ); 
  45. $this->availability = $this->get_option( 'availability' ); 
  46. $this->countries = $this->get_option( 'countries' ); 
  47.  
  48. add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 
  49.  
  50. /** 
  51. * calculate_shipping function. 
  52. * @param array $package (default: array()) 
  53. */ 
  54. public function calculate_shipping( $package = array() ) { 
  55. $shipping_total = 0; 
  56.  
  57. switch ( $this->type ) { 
  58. case 'fixed' : 
  59. $shipping_total = $this->fee; 
  60. break; 
  61. case 'percent' : 
  62. $shipping_total = $package['contents_cost'] * ( $this->fee / 100 ); 
  63. break; 
  64. case 'product' : 
  65. foreach ( $package['contents'] as $item_id => $values ) { 
  66. if ( $values['quantity'] > 0 && $values['data']->needs_shipping() ) { 
  67. $shipping_total += $this->fee * $values['quantity']; 
  68. break; 
  69.  
  70. $rate = array( 
  71. 'id' => $this->id,  
  72. 'label' => $this->title,  
  73. 'cost' => $shipping_total,  
  74. 'package' => $package,  
  75. ); 
  76.  
  77. $this->add_rate( $rate ); 
  78.  
  79. /** 
  80. * Init form fields. 
  81. */ 
  82. public function init_form_fields() { 
  83. $this->form_fields = array( 
  84. 'enabled' => array( 
  85. 'title' => __( 'Enable', 'woocommerce' ),  
  86. 'type' => 'checkbox',  
  87. 'label' => __( 'Once disabled, this legacy method will no longer be available.', 'woocommerce' ),  
  88. 'default' => 'no',  
  89. ),  
  90. 'title' => array( 
  91. 'title' => __( 'Title', 'woocommerce' ),  
  92. 'type' => 'text',  
  93. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),  
  94. 'default' => __( 'Local delivery', 'woocommerce' ),  
  95. 'desc_tip' => true,  
  96. ),  
  97. 'type' => array( 
  98. 'title' => __( 'Fee type', 'woocommerce' ),  
  99. 'type' => 'select',  
  100. 'class' => 'wc-enhanced-select',  
  101. 'description' => __( 'How to calculate delivery charges', 'woocommerce' ),  
  102. 'default' => 'fixed',  
  103. 'options' => array( 
  104. 'fixed' => __( 'Fixed amount', 'woocommerce' ),  
  105. 'percent' => __( 'Percentage of cart total', 'woocommerce' ),  
  106. 'product' => __( 'Fixed amount per product', 'woocommerce' ),  
  107. ),  
  108. 'desc_tip' => true,  
  109. ),  
  110. 'fee' => array( 
  111. 'title' => __( 'Delivery fee', 'woocommerce' ),  
  112. 'type' => 'price',  
  113. 'description' => __( 'What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.', 'woocommerce' ),  
  114. 'default' => '',  
  115. 'desc_tip' => true,  
  116. 'placeholder' => wc_format_localized_price( 0 ),  
  117. ),  
  118. 'codes' => array( 
  119. 'title' => __( 'Allowed ZIP/post codes', 'woocommerce' ),  
  120. 'type' => 'text',  
  121. 'desc_tip' => __( 'What ZIP/post codes are available for local delivery?', 'woocommerce' ),  
  122. 'default' => '',  
  123. 'description' => __( 'Separate codes with a comma. Accepts wildcards, e.g. <code>P*</code> will match a postcode of PE30. Also accepts a pattern, e.g. <code>NG1___</code> would match NG1 1AA but not NG10 1AA', 'woocommerce' ),  
  124. 'placeholder' => 'e.g. 12345, 56789',  
  125. ),  
  126. 'availability' => array( 
  127. 'title' => __( 'Method availability', 'woocommerce' ),  
  128. 'type' => 'select',  
  129. 'default' => 'all',  
  130. 'class' => 'availability wc-enhanced-select',  
  131. 'options' => array( 
  132. 'all' => __( 'All allowed countries', 'woocommerce' ),  
  133. 'specific' => __( 'Specific Countries', 'woocommerce' ),  
  134. ),  
  135. ),  
  136. 'countries' => array( 
  137. 'title' => __( 'Specific countries', 'woocommerce' ),  
  138. 'type' => 'multiselect',  
  139. 'class' => 'wc-enhanced-select',  
  140. 'css' => 'width: 400px;',  
  141. 'default' => '',  
  142. 'options' => WC()->countries->get_shipping_countries(),  
  143. 'custom_attributes' => array( 
  144. 'data-placeholder' => __( 'Select some countries', 'woocommerce' ),  
  145. ),  
  146. ),  
  147. );