WP SITES

3087 Coded Tutorials & 293 Plugins

How To Use World Wide Shipping Method With Multiple Zones

To use worldwide shipping when using multiple zones, you need to add the worldwide shipping method to each zone.

In this example, we have 3 zones :

  • United States
  • Australia
  • Rest of the World

We want to add a shipping method which is available for customers globally ( world wide ) so we need to add exactly the same shipping method to each zone as seen in the following image :

In the above image, you’ll see Regular Mail $6 which is the world wide shipping method we have added to each shipping zone.

This global shipping method will display on the cart page regardless of the customer address.

Conditional Shipping

The following code enables you to control when the method is displayed. In this example, we only want it displayed if the cart total is under $150.

add_filter('woocommerce_package_rates', 'wpsites_remove_flat_rate_methods_over_150', 10, 2);
function wpsites_remove_flat_rate_methods_over_150($rates, $package) {

    $cart_total = WC()->cart->get_cart_contents_total();
    
    $threshold = 150;

    // Define the shipping method IDs to remove if cart total exceeds $150
    $methods_to_remove = array(
        'flat_rate:12',
        'flat_rate:13',
        'flat_rate:14'
    );

    // Check if the cart total exceeds the threshold
    if ($cart_total > $threshold) {
        // Loop through the rates and unset the ones to remove
        foreach ($rates as $rate_id => $rate) {
            if (in_array($rate_id, $methods_to_remove)) {
                unset($rates[$rate_id]);
            }
        }
    }

    return $rates;
}

Note : You will need to swap out the shipping method ids in the above code to match what you have setup on your installation.

How to find shipping method ids.

Leave a Reply

New Plugins