In this tutorial, we will show you how to restrict WooCommerce product variations by city.
This will allow you to sell certain variations of the same product to specific cities only, and hide them for the other cities.
For this, we will use the WooCommerce Product Variations by City plugin.
With this plugin you will be able to restrict products, variations, category and attribute pages, and discount coupons by city, state, province, zip code, etc.
You can download the plugin here:
Download WooCommerce Product Restrictions by Zip Code Plugin - or - Read more
After installing and activating the plugin, follow the steps below to restrict WooCommerce product variations by city.
Set up the variation restrictions by city method on the global settings
The first thing you need to do is to set up what you want to restrict and how you want to restrict it. In this case, we will restrict variations by city.
For this, go to WooCommerce > Product Resrictions by Location and hit Open global settings.
You can also open this page by going to WooCommerce > Settings > Restrictions by location.
Once you’re there, select the following values to enable the variations by city restriction method:
- I want to restrict: Products and variations
- I want to restrict by: Custom list of locations
- Please enter the list of locations that you will allow your customers to select: Add one city at a time and hit Add location.
- What happens when the user location is restricted: You can hide or show all products.
- Once you’re done, click on Save changes.
Option 1 – Restrict variations by city globally
You can select which variations can be viewed by specific cities by selecting the cities and the combination of attributes these variations must have.
Go to the Variations per location tab in the global settings of the plugin, and you’ll see that you can add rule groups. This is useful to add several variations.
For example, let’s add a rule group that states that the products containing the black color and large size attributes will be hidden for Houston, Chandler, and Portland.
For this, we need to select the following values:
- Select location: We need to enter the cities here.
- Select attributes: We need to add the pa_color:Black and pa_size:Large attributes here.
- Sell product variations in the selected locations:
- If you select YES, it means that all variations composed of the attributes black and large will be visible only for the selected cities. These cities will not see other variations.
- If you select NO, it means that variations with the selected attributes will be visible for all cities, except for the selected cities.
For example, in this case we select the Large Black variations to be hidden for Houston, Chandler and Portland. And when we visit the store as a normal user, we will see that the selected attributes do not appear because the variations with those attributes are restricted for these cities.
On the contrary, if we select another city such as Garland, we will see that this city only sees products with the attributes Black and Large. This is due to what we explained above.
Option 2 – Restrict variations by city individually
If you don’t want to apply a global restriction like the one we have explained, you can open a specific WooCommerce product, and restrict specific variations of that product for specific cities.
In this example, we will hide the variation with the Black and Large attributes for Houston, Chandler and Portland.
Once you open the product, go to the variation you want to restrict by city under Location restrictions, and select the following values:
- Selected locations: Select the cities here.
- Available in selected locations: No
- Scroll down and hit Save changes.
- Hit Update to apply the changes to the product.
As you can see in the screenshot below, if we select Houston, which is one of the blocked cities, the Black and Large attributes will disappear from the dropdowns.
The WooCommerce Product Restrictions by City plugin allows you to restrict your variations by city globally and individually. This is a great way to segment the sale of your product variations.
You can download the plugin here:
Download WooCommerce Product Restrictions by Zip Code Plugin - or - Read more