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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / settings / class-wc-settings-shipping.php
woocommerce / includes / admin / settings Last commit date
views 1 month ago class-wc-settings-accounts.php 5 months ago class-wc-settings-advanced.php 1 month ago class-wc-settings-checkout.php 5 years ago class-wc-settings-emails.php 1 month ago class-wc-settings-general.php 1 month ago class-wc-settings-integrations.php 1 year ago class-wc-settings-page.php 1 week ago class-wc-settings-payment-gateways.php 1 week ago class-wc-settings-point-of-sale.php 3 months ago class-wc-settings-products.php 1 month ago class-wc-settings-shipping.php 3 months ago class-wc-settings-site-visibility.php 2 years ago class-wc-settings-tax.php 5 months ago
class-wc-settings-shipping.php
539 lines
1 <?php
2 /**
3 * WooCommerce Shipping Settings
4 *
5 * @package WooCommerce\Admin
6 * @version 2.6.0
7 */
8
9 use Automattic\Jetpack\Constants;
10 use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
11 use Automattic\WooCommerce\Utilities\FeaturesUtil;
12
13 defined( 'ABSPATH' ) || exit;
14
15 if ( class_exists( 'WC_Settings_Shipping', false ) ) {
16 return new WC_Settings_Shipping();
17 }
18
19 /**
20 * WC_Settings_Shipping.
21 */
22 class WC_Settings_Shipping extends WC_Settings_Page {
23
24 /**
25 * Constructor.
26 */
27 public function __construct() {
28 $this->id = 'shipping';
29 $this->label = __( 'Shipping', 'woocommerce' );
30
31 parent::__construct();
32 }
33
34 /**
35 * Setting page icon.
36 *
37 * @var string
38 */
39 public $icon = 'shipping';
40
41 /**
42 * Add this page to settings.
43 *
44 * @param array $pages Current pages.
45 * @return array|mixed
46 */
47 public function add_settings_page( $pages ) {
48 return wc_shipping_enabled() ? parent::add_settings_page( $pages ) : $pages;
49 }
50
51 /**
52 * Get own sections.
53 *
54 * @return array
55 */
56 protected function get_own_sections() {
57 $sections = array(
58 '' => __( 'Shipping zones', 'woocommerce' ),
59 'options' => __( 'Shipping settings', 'woocommerce' ),
60 'classes' => __( 'Classes', 'woocommerce' ),
61 );
62
63 if ( FeaturesUtil::feature_is_enabled( 'fulfillments' ) ) {
64 $sections['fulfillment-providers'] = __( 'Shipping providers', 'woocommerce' );
65 }
66
67 if ( ! $this->wc_is_installing() ) {
68 // Load shipping methods so we can show any global options they may have.
69 $shipping_methods = $this->get_shipping_methods();
70
71 foreach ( $shipping_methods as $method ) {
72 if ( ! $method->has_settings() ) {
73 continue;
74 }
75 $title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title;
76 $sections[ strtolower( $method->id ) ] = esc_html( $title );
77 }
78 }
79
80 return $sections;
81 }
82
83 /**
84 * Is WC_INSTALLING constant defined?
85 * This method exists to ease unit testing.
86 *
87 * @return bool True is the WC_INSTALLING constant is defined.
88 */
89 protected function wc_is_installing() {
90 return Constants::is_defined( 'WC_INSTALLING' );
91 }
92
93 /**
94 * Get the currently available shipping methods.
95 * This method exists to ease unit testing.
96 *
97 * @return array Currently available shipping methods.
98 */
99 protected function get_shipping_methods() {
100 return WC()->shipping()->get_shipping_methods();
101 }
102
103 /**
104 * Get settings for the options section.
105 *
106 * @return array
107 */
108 protected function get_settings_for_options_section() {
109 $settings =
110 array(
111 array(
112 'title' => __( 'Shipping settings', 'woocommerce' ),
113 'type' => 'title',
114 'id' => 'shipping_options',
115 ),
116
117 array(
118 'title' => __( 'Calculations', 'woocommerce' ),
119 'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
120 'id' => 'woocommerce_enable_shipping_calc',
121 'default' => 'yes',
122 'type' => 'checkbox',
123 'checkboxgroup' => 'start',
124 'autoload' => false,
125 ),
126
127 array(
128 'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
129 'id' => 'woocommerce_shipping_cost_requires_address',
130 'default' => 'no',
131 'type' => 'checkbox',
132 'checkboxgroup' => '',
133 ),
134
135 array(
136 'desc' => __( 'Hide shipping rates when free shipping is available', 'woocommerce' ),
137 'id' => 'woocommerce_shipping_hide_rates_when_free',
138 'default' => 'no',
139 'type' => 'checkbox',
140 'autoload' => false,
141 'checkboxgroup' => 'end',
142 ),
143
144 array(
145 'title' => __( 'Shipping destination', 'woocommerce' ),
146 'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
147 'id' => 'woocommerce_ship_to_destination',
148 'default' => 'billing',
149 'type' => 'radio',
150 'options' => array(
151 'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
152 'billing' => __( 'Default to customer billing address', 'woocommerce' ),
153 'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
154 ),
155 'autoload' => false,
156 'desc_tip' => true,
157 'show_if_checked' => 'option',
158 ),
159
160 array(
161 'title' => __( 'Debug mode', 'woocommerce' ),
162 'desc' => __( 'Enable debug mode', 'woocommerce' ),
163 'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
164 'id' => 'woocommerce_shipping_debug_mode',
165 'default' => 'no',
166 'type' => 'checkbox',
167 ),
168
169 array(
170 'type' => 'sectionend',
171 'id' => 'shipping_options',
172 ),
173 );
174
175 return apply_filters( 'woocommerce_shipping_settings', $settings );
176 }
177
178 /**
179 * Output the settings.
180 */
181 public function output() {
182 global $current_section, $hide_save_button;
183
184 // Load shipping methods so we can show any global options they may have.
185 $shipping_methods = $this->get_shipping_methods();
186
187 if ( '' === $current_section ) {
188 $this->output_zones_screen();
189 } elseif ( 'classes' === $current_section ) {
190 $hide_save_button = true;
191 $this->output_shipping_class_screen();
192 } elseif ( 'fulfillment-providers' === $current_section && FeaturesUtil::feature_is_enabled( 'fulfillments' ) ) {
193 $hide_save_button = true;
194 $this->output_shipping_providers_screen();
195 } else {
196 $is_shipping_method = false;
197 foreach ( $shipping_methods as $method ) {
198 if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ), true ) && $method->has_settings() ) {
199 $is_shipping_method = true;
200 $method->admin_options();
201 }
202 }
203 if ( ! $is_shipping_method ) {
204 parent::output();
205 }
206 }
207 }
208
209 /**
210 * Save settings.
211 */
212 public function save() {
213 global $current_section;
214
215 switch ( $current_section ) {
216 case 'options':
217 $this->save_settings_for_current_section();
218 $this->do_update_options_action();
219 break;
220 case 'classes':
221 $this->do_update_options_action();
222 break;
223 case 'fulfillment-providers':
224 if ( FeaturesUtil::feature_is_enabled( 'fulfillments' ) ) {
225 $this->do_update_options_action();
226 }
227 break;
228 case '':
229 break;
230 default:
231 $is_shipping_method = false;
232
233 foreach ( $this->get_shipping_methods() as $method_id => $method ) {
234 if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ), true ) ) {
235 $is_shipping_method = true;
236 $this->do_update_options_action( $method->id );
237 }
238 }
239 if ( ! $is_shipping_method ) {
240 $this->save_settings_for_current_section();
241 }
242 break;
243 }
244
245 // Increments the transient version to invalidate cache.
246 WC_Cache_Helper::get_transient_version( 'shipping', true );
247 }
248
249 /**
250 * Handles output of the shipping zones page in admin.
251 */
252 protected function output_zones_screen() {
253 // phpcs:disable WordPress.Security.NonceVerification.Recommended
254 global $hide_save_button;
255
256 if ( isset( $_REQUEST['zone_id'] ) ) {
257 $hide_save_button = true;
258 $this->zone_methods_screen( wc_clean( wp_unslash( $_REQUEST['zone_id'] ) ) );
259 } elseif ( isset( $_REQUEST['instance_id'] ) ) {
260 $this->instance_settings_screen( absint( wp_unslash( $_REQUEST['instance_id'] ) ) );
261 } else {
262 $hide_save_button = true;
263 $this->zones_screen();
264 }
265 // phpcs:enable WordPress.Security.NonceVerification.Recommended
266 }
267
268 /**
269 * Get all available regions.
270 *
271 * @param int $allowed_countries Zone ID.
272 * @param int $shipping_continents Zone ID.
273 */
274 protected function get_region_options( $allowed_countries, $shipping_continents ) {
275 $options = array();
276 foreach ( $shipping_continents as $continent_code => $continent ) {
277 $continent_data = array(
278 'value' => 'continent:' . esc_attr( $continent_code ),
279 'label' => esc_html( $continent['name'] ),
280 'children' => array(),
281 );
282
283 $countries = array_intersect( array_keys( $allowed_countries ), $continent['countries'] );
284
285 foreach ( $countries as $country_code ) {
286 $country_data = array(
287 'value' => 'country:' . esc_attr( $country_code ),
288 'label' => esc_html( $allowed_countries[ $country_code ] ),
289 'children' => array(),
290 );
291
292 $states = WC()->countries->get_states( $country_code );
293
294 if ( $states ) {
295 foreach ( $states as $state_code => $state_name ) {
296 $country_data['children'][] = array(
297 'value' => 'state:' . esc_attr( $country_code . ':' . $state_code ),
298 'label' => esc_html( $state_name . ', ' . $allowed_countries[ $country_code ] ),
299 );
300 }
301 }
302 $continent_data['children'][] = $country_data;
303 }
304 $options[] = $continent_data;
305 }
306
307 return $options;
308 }
309
310 /**
311 * Show method for a zone
312 *
313 * @param int $zone_id Zone ID.
314 */
315 protected function zone_methods_screen( $zone_id ) {
316 if ( 'new' === $zone_id ) {
317 $zone = new WC_Shipping_Zone();
318 } else {
319 $zone = WC_Shipping_Zones::get_zone( absint( $zone_id ) );
320 }
321
322 if ( ! $zone ) {
323 wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) );
324 }
325
326 $allowed_countries = WC()->countries->get_shipping_countries();
327 $shipping_continents = WC()->countries->get_shipping_continents();
328
329 // Prepare locations.
330 $locations = array();
331 $postcodes = array();
332
333 foreach ( $zone->get_zone_locations() as $location ) {
334 if ( 'postcode' === $location->type ) {
335 $postcodes[] = $location->code;
336 } else {
337 $locations[] = $location->type . ':' . $location->code;
338 }
339 }
340
341 $localized_object = array(
342 'methods' => $zone->get_shipping_methods( false, 'json' ),
343 'zone_name' => $zone->get_zone_name(),
344 'zone_id' => $zone->get_id(),
345 'locations' => $locations,
346 'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
347 'strings' => array(
348 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
349 'save_changes_prompt' => __( 'Do you wish to save your changes first? Your changed data will be discarded if you choose to cancel.', 'woocommerce' ),
350 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
351 'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ),
352 'remove_method_failed' => __( 'Shipping method could not be removed. Please retry.', 'woocommerce' ),
353 'yes' => __( 'Yes', 'woocommerce' ),
354 'no' => __( 'No', 'woocommerce' ),
355 'default_zone_name' => __( 'Zone', 'woocommerce' ),
356 'delete_shipping_method_confirmation' => __( 'Are you sure you want to delete this shipping method?', 'woocommerce' ),
357 'invalid_number_format' => __( 'Please enter a valid number.', 'woocommerce' ),
358 ),
359 );
360
361 if ( 0 !== $zone->get_id() ) {
362 WCAdminAssets::register_script( 'wp-admin-scripts', 'shipping-settings-region-picker', true, array( 'wc-shipping-zone-methods' ) );
363 $localized_object['region_options'] = $this->get_region_options( $allowed_countries, $shipping_continents );
364 }
365
366 wp_localize_script(
367 'wc-shipping-zone-methods',
368 'shippingZoneMethodsLocalizeScript',
369 $localized_object,
370 );
371 wp_enqueue_script( 'wc-shipping-zone-methods' );
372
373 include_once __DIR__ . '/views/html-admin-page-shipping-zone-methods.php';
374 }
375
376 /**
377 * Show zones
378 */
379 protected function zones_screen() {
380 $method_count = wc_get_shipping_method_count( false, true );
381
382 wp_localize_script(
383 'wc-shipping-zones',
384 'shippingZonesLocalizeScript',
385 array(
386 'zones' => WC_Shipping_Zones::get_zones( 'json' ),
387 'default_zone' => array(
388 'zone_id' => 0,
389 'zone_name' => '',
390 'zone_order' => null,
391 ),
392 'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
393 'strings' => array(
394 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
395 'delete_confirmation_msg' => __( 'Are you sure you want to delete this zone? This action cannot be undone.', 'woocommerce' ),
396 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
397 'no_shipping_methods_offered' => __( 'No shipping methods offered to this zone.', 'woocommerce' ),
398 ),
399 )
400 );
401 wp_enqueue_script( 'wc-shipping-zones' );
402
403 include_once __DIR__ . '/views/html-admin-page-shipping-zones.php';
404 }
405
406 /**
407 * Show instance settings
408 *
409 * @param int $instance_id Shipping instance ID.
410 */
411 protected function instance_settings_screen( $instance_id ) {
412 $zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id );
413 $shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
414
415 if ( ! $shipping_method ) {
416 wp_die( esc_html__( 'Invalid shipping method!', 'woocommerce' ) );
417 }
418 if ( ! $zone ) {
419 wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) );
420 }
421 if ( ! $shipping_method->has_settings() ) {
422 wp_die( esc_html__( 'This shipping method does not have any settings to configure.', 'woocommerce' ) );
423 }
424
425 if ( ! empty( $_POST['save'] ) ) {
426
427 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
428 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) {
429 echo '<div class="updated error"><p>' . esc_html__( 'Edit failed. Please try again.', 'woocommerce' ) . '</p></div>';
430 }
431
432 $shipping_method->process_admin_options();
433 $shipping_method->display_errors();
434 }
435
436 include_once __DIR__ . '/views/html-admin-page-shipping-zones-instance.php';
437 }
438
439 /**
440 * Handles output of the shipping class settings screen.
441 */
442 protected function output_shipping_class_screen() {
443 $wc_shipping = WC_Shipping::instance();
444 wp_localize_script(
445 'wc-shipping-classes',
446 'shippingClassesLocalizeScript',
447 array(
448 'classes' => $wc_shipping->get_shipping_classes(),
449 'default_shipping_class' => array(
450 'term_id' => 0,
451 'name' => '',
452 'description' => '',
453 ),
454 'wc_shipping_classes_nonce' => wp_create_nonce( 'wc_shipping_classes_nonce' ),
455 'strings' => array(
456 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
457 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
458 ),
459 )
460 );
461 wp_enqueue_script( 'wc-shipping-classes' );
462
463 // Extendable columns to show on the shipping classes screen.
464 $shipping_class_columns = apply_filters(
465 'woocommerce_shipping_classes_columns',
466 array(
467 'wc-shipping-class-name' => __( 'Shipping class', 'woocommerce' ),
468 'wc-shipping-class-slug' => __( 'Slug', 'woocommerce' ),
469 'wc-shipping-class-description' => __( 'Description', 'woocommerce' ),
470 'wc-shipping-class-count' => __( 'Product count', 'woocommerce' ),
471 )
472 );
473
474 include_once __DIR__ . '/views/html-admin-page-shipping-classes.php';
475 }
476
477 /**
478 * Handles output of the shipping providers settings screen.
479 *
480 * @since 10.7.0
481 */
482 protected function output_shipping_providers_screen(): void {
483 $providers = get_terms(
484 array(
485 'taxonomy' => 'wc_fulfillment_shipping_provider',
486 'hide_empty' => false,
487 )
488 );
489
490 if ( is_wp_error( $providers ) ) {
491 $providers = array();
492 }
493
494 $shipping_providers = array();
495 foreach ( $providers as $provider ) {
496 $shipping_providers[] = array(
497 'term_id' => $provider->term_id,
498 'name' => $provider->name,
499 'slug' => $provider->slug,
500 'tracking_url_template' => get_term_meta( $provider->term_id, 'tracking_url_template', true ),
501 'icon' => get_term_meta( $provider->term_id, 'icon', true ),
502 );
503 }
504
505 wp_localize_script(
506 'wc-shipping-providers',
507 'shippingProvidersLocalizeScript',
508 array(
509 'providers' => $shipping_providers,
510 'default_shipping_provider' => array(
511 'term_id' => 0,
512 'name' => '',
513 'slug' => '',
514 'tracking_url_template' => '',
515 'icon' => '',
516 ),
517 'wc_shipping_providers_nonce' => wp_create_nonce( 'wc_shipping_providers_nonce' ),
518 'strings' => array(
519 'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
520 'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
521 'delete_confirmation' => __( 'Are you sure you want to delete this shipping provider?', 'woocommerce' ),
522 ),
523 )
524 );
525 wp_enqueue_script( 'wc-shipping-providers' );
526
527 $shipping_provider_columns = array(
528 'wc-shipping-provider-name' => __( 'Name', 'woocommerce' ),
529 'wc-shipping-provider-slug' => __( 'Slug', 'woocommerce' ),
530 'wc-shipping-provider-tracking-url-template' => __( 'Tracking URL template', 'woocommerce' ),
531 'wc-shipping-provider-icon' => __( 'Icon URL', 'woocommerce' ),
532 );
533
534 include_once __DIR__ . '/views/html-admin-page-shipping-providers.php';
535 }
536 }
537
538 return new WC_Settings_Shipping();
539