WooCommerce – Restrict Products by City (Billing or Shipping)

In this post, we’ll show you how to restrict WooCommerce products by city. You’ll learn how to sell products to specific cities or ban other cities from these products.

This can be really useful when you don’t ship your products to a specific city in a specific country, and you don’t want the customers to be able to place the order in your WooCommerce store.

Instead, you want to redirect them to a specific URL or show them an error message telling them the product isn’t available for their countries.

We’ll do it using the WordPress Conditional Post Restrictions plugin.

It allows you to restrict or allow access to your posts, products, products, downloads, courses, events, forums, recipes, and any other custom post type.

You don’t need to program anything nor hire an experienced programmer because you can create conditional restrictions for your products with a few clicks and using just some fields.

Once you install and activate the plugin, you need to follow the steps in this guide to restrict all products, individual products, and product categories by shipping or billing city.

1- How to restrict all WooCommerce products by shipping/billing city

First, we’ll show you how to restrict all your WooCommerce products by shipping or billing city. This works perfectly when you don’t want to sell any product to a specific city in a specific country. You need to apply a global conditional restriction.

Just follow these steps:

  1. Go to Settings > Post Restrictions.
  2. Click Add Conditions to create a new global condition.

restrict products by city woocommerce

Now you need to select the following values to restrict all the WooCommerce products for a specific city:

  • Add new restrictions: Enter the restriction title.
  • Select post types: Products
  • What happens when the restrictions are met: Restrict access or Allow access
  • Condition 1: Shipping country or Billing country | = | United States, for example.
  • Click + to add a new condition.
  • Condition 1: Shipping city or Billing city | = | Seattle, for example
  • Publish the condition.

restrict products by city woocommerce

Important

  • As you see, we’ve selected the country first, and this is important because sometimes there may be countries with cities that have the same names. So we need to be specific about which country we want to affect with this restriction. That’s why we’ve added an “and” condition.

2- How to restrict specific WooCommerce products by shipping/billing city

If you don’t want to restrict all products by billing or shipping city, you can restrict only specific products. For example, there are cities where a certain product may be illegal, so we may need to restrict that specific product only so users aren’t able to include it in their orders.

Just follow these simple steps:

  1. Go to Products > All Products.
  2. Open the product you want to edit.

restrict products by city woocommerce

Once you open the product you want to edit, scroll down to the Restriction Rules section in the product editor, and select these simple steps to restrict this specific product by shipping or billing city:

  • Enable content restrictions: Yes
  • What happens when the restrictions are met: Restrict access or Allow access
  • Condition 1: Shipping country or Billing country | = | United States, for example.
  • Click + to add a new condition.
  • Condition 1: Shipping city or Billing city | = | Seattle, for example
  • Update the product to save the changes.

restrict products by city woocommerce

Important

  • As you see, we’ve selected the country first, and this is important because sometimes there may be countries with cities that have the same names. So we need to be specific about which country we want to affect with this restriction. That’s why we’ve added an “and” condition.
  • Also, it’s important to mention that you need to edit other products individually to restrict them as well. You can select any other cities for other products as the condition will apply to them only.

3- How to restrict product categories by shipping or billing city

Restricting all products would be too much if you still want to sell products in a city, and restricting a lot of products individually would be kind of tedious maybe. That’s why in this section we show you how to restrict product categories by shipping or billing country. With this, you can restrict all the products within an entire category.

Follow these simple steps:

  1. Go to Products > Categories.
  2. Open the category you want to edit.

restrict products by city woocommerce

Once you open the category you want to edit, you need to tick the Enable the conditional restrictions checkbox, and select the following values to restrict this entire category by shipping or billing city.

  • Apply restrictions to: Category and posts
  • What happens when the conditions are met: Restrict access or Allow access
  • Condition 1: Shipping country or Billing country | = | United States, for example.
  • Click + to add a new condition.
  • Condition 1: Shipping city or Billing city | = | Seattle, for example
  • Update the category to save the changes.

restrict products by city woocommerce

Important

  • As you see, we’ve selected the country first, and this is important because sometimes there may be countries with cities that have the same names. So we need to be specific about which country we want to affect with this restriction. That’s why we’ve added an “and” condition.
  • All the products within this category will be affected by this restriction.

4-What if customers try to buy products that are not allowed in the billing/shipping city?

You can select what happens when customers don’t meet the required conditions to buy products; that is, when customers are in the cities for which the products are not allowed.

  • Go to Settings > Post restrictions.

Once there, you’ll see these fields and options:

restrict products by city woocommerce

  • Enable restrictions: Tick/untick this checkbox to enable/disable the global conditions.
  • Don’t apply restrictions for these user roles: You’ll see a list of user roles for which the conditions won’t be applied. By default, we will not apply restrictions for administrators, editors, and any user with the capability edit_others_posts.
  • What happens when the post is restricted? You have several options to select what happens when the post is restricted:
    • Redirect to URL
    • Remove the content and show a message
    • Show fragment of the content and show message after fragment
  • What happens when a category is restricted? You have several options to select what happens when the post is restricted:
    • Show error 404
    • Show the normal page without posts
    • Show an error message
    • Redirect to another URL
    • Show the content of another page

Once you select the global settings, just save the changes.

That’s really easy!

As you see, restricting WooCommerce products by shipping or billing city is really easy with the WordPress Conditional Post Restrictions plugin. With a few clicks, you can apply advanced restrictions to your posts, pages, products, etc.

Close Menu