How to Block WooCommerce Sales by Location – Effective Regional Restrictions

October 11, 2024

Anne Allen

Learn how to restrict WooCommerce sales to certain regions, ensuring seamless compliance with your business needs. This method works on the cart page created with the ‘Woocommerce-cart’ shortcode but does not apply to the new Cart Block.

Block WooCommerce Sales by Location

Running a WooCommerce store can be challenging when you need to restrict sales to specific locations. Whether due to legal reasons, shipping limitations, or tax regulations, certain regions may need to be excluded from your service area. Unfortunately, WooCommerce doesn’t offer an easy, built-in option for this functionality, leaving many store owners frustrated when trying to comply with regional restrictions.

Without a reliable method to block sales to unwanted locations, you risk dealing with issues like customer confusion, failed order fulfillment, or worse—legal trouble due to unauthorized sales. Many WooCommerce users struggle to find a solution that works seamlessly without breaking their store’s checkout flow. If you’re using the ‘Woocommerce-cart’ shortcode for your cart page, figuring out how to manage these restrictions can feel like navigating a minefield.

Thankfully, there’s an effective method to block WooCommerce sales by location, tailored to work with the cart page created using the [Woocommerce-cart] shortcode. This ensures that when customers from restricted regions attempt to purchase, they’ll be prevented from completing their orders, all while maintaining the smooth experience for approved locations.

Note that this Block WooCommerce Sales by Location method does not apply to WooCommerce’s newer Cart Block feature – I will update this method when I figure that out

Step to take

Step 1: Setup a Shipping Zone to cover only the allowed locations

In the screenshot below, this shipping Zone “US Allowed States” contains only the states that products can be shipped to (this could be countries or regions)

Block WooCommerce Sales by Location

Step 2: Add code functions.php to remove the “Proceed to checkout” link from the Cart page

remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );

Step 3: Add code to add the “Proceed to checkout” link back in, only if the shipping address matches a location in the allowed zone(s)

add_action( 'woocommerce_proceed_to_checkout', 'stm_woo_button_proceed_to_checkout', 20 );

function stm_woo_button_proceed_to_checkout(){
	if (WC()->cart->needs_shipping()) {
        $packages = WC()->cart->get_shipping_packages();
        $zone = WC_Shipping_Zones::get_zone_matching_package($packages[0]);
	}
	if ($zone->get_id() == 1) { //Zone 1 is my "US Allowed States" 
		woocommerce_button_proceed_to_checkout(); //This will render the Proceed to checkout link
	}
	else {
		echo 'We cannot ship to this location';
	}
}

Benefits of Using This Location-Based Sales Blocking Solution

  1. Location-Based Control
    Easily block sales from specific regions to ensure compliance with legal and logistical requirements.
  2. Shortcode Compatibility
    This solution works seamlessly with the ‘Woocommerce-cart’ shortcode, ensuring it integrates with your existing cart page setup.
  3. Prevent Unauthorized Sales
    Automatically prevent customers from restricted regions from completing purchases, reducing the risk of order disputes.
  4. Customizable Restrictions
    Tailor which regions or countries are restricted based on your unique business needs, providing flexibility.
  5. Seamless Checkout Flow
    Maintains the checkout experience for approved customers, ensuring no disruptions to your main target market.
  6. No Need for Complex Plugins
    Avoid unnecessary, bulky plugins by using a direct solution that doesn’t complicate your store.
  7. Legal Compliance
    Stay compliant with international laws by effectively managing regional restrictions, avoiding fines and penalties.
  8. Reduced Shipping Hassles
    Minimize errors in shipping to locations where you don’t operate, saving time and resources on order fulfillment.
  9. Cart Page Focused
    Applies directly to the cart page built using ‘Woocommerce-cart’ shortcode, ensuring it works for legacy WooCommerce setups.
  10. User-Friendly Configuration
    Easy-to-configure method without complex coding, making it accessible for most WooCommerce store owners.

Prevent sales to specific regions using the ‘Woocommerce-cart’ shortcode. For tailored WooCommerce solutions, Nustart Solutions is here to help.

As notes above, this solution will not work if you are using the newer Woocommerce Cart Block. The new WooCommerce Cart Block offers a modernized, flexible approach to displaying the cart page.

The advantage of the new cart block is that it allows for enhanced customization and greater control over design without needing custom coding. With a drag-and-drop interface, it integrates seamlessly with the block editor, making it easier to adjust the layout, apply styling, and even add features like cross-sells or discount messages.

However, some existing plugins and methods, such as location-based sales restrictions, do not yet fully support the Cart Block, so careful testing is recommended before implementing it across your store.

Anne Allen

About the author

Hi, I’m Anne Allen. I’ve spent the last 15 years living and breathing WordPress. I’m passionate about helping business owners demystify their websites—whether that means keeping your site secure with proper maintenance, setting up complex Gravity Forms, or ensuring your content is accessible through ADA compliance. Let’s make your site work for you.