get_zone_matching_package() public static method

Find a matching zone for a given package.
Since: 2.6.0
public static get_zone_matching_package ( object $package ) : WC_Shipping_Zone
$package object
return WC_Shipping_Zone
Exemplo n.º 1
0
 /**
  * Test: WC_Shipping_Zones::get_zone_matching_package
  */
 public function test_get_zone_matching_package()
 {
     // Setup
     WC_Helper_Shipping_Zones::create_mock_zones();
     // Test
     $zone1 = WC_Shipping_Zones::get_zone_matching_package(array('destination' => array('country' => 'GB', 'state' => 'Cambs', 'postcode' => 'CB23 1GG')));
     $zone2 = WC_Shipping_Zones::get_zone_matching_package(array('destination' => array('country' => 'GB', 'state' => 'Cambs', 'postcode' => 'PE12 1BG')));
     $zone3 = WC_Shipping_Zones::get_zone_matching_package(array('destination' => array('country' => 'US', 'state' => 'CA', 'postcode' => '90210')));
     $zone4 = WC_Shipping_Zones::get_zone_matching_package(array('destination' => array('country' => 'US', 'state' => 'AL', 'postcode' => '12345')));
     // Assert
     $this->assertEquals('Local', $zone1->get_zone_name());
     $this->assertEquals('Europe', $zone2->get_zone_name());
     $this->assertEquals('California', $zone3->get_zone_name());
     $this->assertEquals('US', $zone4->get_zone_name());
     // Clean
     WC_Helper_Shipping_Zones::remove_mock_zones();
 }
Exemplo n.º 2
0
 /**
  * Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally.
  *
  * Loads all shipping methods which are hooked in.
  * If a $package is passed some methods may add themselves conditionally and zones will be used.
  *
  * @param array $package
  * @return array
  */
 public function load_shipping_methods($package = array())
 {
     if (!empty($package)) {
         $status_options = get_option('woocommerce_status_options', array());
         $shipping_zone = WC_Shipping_Zones::get_zone_matching_package($package);
         $this->shipping_methods = $shipping_zone->get_shipping_methods(true);
         // Debug output
         if (!empty($status_options['shipping_debug_mode']) && !defined('WOOCOMMERCE_CHECKOUT') && !wc_has_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"')) {
             wc_add_notice('Customer matched zone "' . $shipping_zone->get_zone_name() . '"');
         }
     } else {
         $this->shipping_methods = array();
     }
     // For the settings in the backend, and for non-shipping zone methods, we still need to load any registered classes here.
     foreach ($this->get_shipping_method_class_names() as $method_id => $method_class) {
         $this->register_shipping_method($method_class);
     }
     // Methods can register themselves manually through this hook if necessary.
     do_action('woocommerce_load_shipping_methods', $package);
     // Return loaded methods
     return $this->get_shipping_methods();
 }
Exemplo n.º 3
0
 /**
  * Get the shipping zone matching a given package from the cart.
  *
  * @since  2.6.0
  * @uses   WC_Shipping_Zones::get_zone_matching_package
  * @param  array $package
  * @return WC_Shipping_Zone
  */
 function wc_get_shipping_zone($package)
 {
     return WC_Shipping_Zones::get_zone_matching_package($package);
 }
 /**
  * Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally.
  *
  * Loads all shipping methods which are hooked in.
  * If a $package is passed some methods may add themselves conditionally and zones will be used.
  *
  * @param array $package
  * @return array
  */
 public function load_shipping_methods($package = array())
 {
     if (!empty($package)) {
         $shipping_zone = WC_Shipping_Zones::get_zone_matching_package($package);
         $this->shipping_methods = $shipping_zone->get_shipping_methods(true);
     } else {
         $this->shipping_methods = array();
     }
     // For the settings in the backend, and for non-shipping zone methods, we still need to load any registered classes here.
     foreach ($this->get_shipping_method_class_names() as $method_id => $method_class) {
         $this->register_shipping_method($method_class);
     }
     // Methods can register themselves manually through this hook if necessary.
     do_action('woocommerce_load_shipping_methods', $package);
     // Return loaded methods
     return $this->get_shipping_methods();
 }