In this tutorial, we will show you how to restrict WooCommerce categories by state or province. This is useful, for example, if you want to sell all products for all states in the United States, but restrict the “Technology” category for specific states.
We will do this using the WooCommerce Product Restrictions by States and Provinces plugin.
It allows you to restrict WooCommerce products by states or provinces of a specific country. You can restrict specific products, all products globally, entire categories, product variations and discount coupons. This allows you to create catalogs for specific states or provinces. Besides, it allows you to show different product descriptions in different states or provinces.
You can download the plugin here: Download WooCommerce Product Restrictions by State and Provinces Plugin - or - Read more
Once you install and activate the plugin, follow these simple steps:
Step 1. Set up the global settings to restrict WooCommerce categories by state or province
We will start by setting up some global settings that will allow us to restrict product categories by state or province.
Go to WooCommerce > Settings > Country Restrictions.
Once there, select the following values under the General settings tab:
- In I want to restrict, make sure you tick the Category and attribute pages checkbox.
- In I want to restrict by, make sure you select States/provinces from one location
- Next, you need to select the states you want to allow your users to select when visiting your website.
- In What happens when the user location is unknown, select if you want to show or hide the products.
- Click on Save changes.
Some important notes:
- The restriction by state does not work with IP geolocation (automatic detection) because the automatic detection is unreliable for small states, it only works with the dropdown selector (the user selects the state in the dropdown on the header), billing state, and shipping state.
- The list of states will be from the “base country” defined in the WooCommerce settings. To change the base country, go to WooCommerce > Settings > General > Store Address > Country.
Step 2. Restrict your categories by state or province
Once you’ve selected the global state and province restrictions, you can proceed to restrict your categories by state or province.
Go to Products > Categories in wp-admin, and open the category you want to edit.
Now you need to select the following values to restrict your selected category:
- Select locations: Here you need to select the states where your categories will be restricted.
- Available in selected countries: No
- Apply this to: Category and products
- Hit Save to apply the changes.
Once you restrict a specific category, it will disappear from the website and the store page. For example, we have restricted the Accessories category.
When users visit your store, they will see a popup where they can select their state or province.
If the customers select any of the states where your category is not restricted, it appears without any problems in the navigation menu and sidebars.
However, if they select any of the restricted countries, they will see that the restricted category will disappear completely from the site.
Restricting WooCommerce categories by state or province is really simple if you use the WooCommerce Product Restrictions by States and Provinces plugin.
You can download the plugin here: Download WooCommerce Product Restrictions by State and Provinces Plugin - or - Read more