Product Category Permalinks in WooCommerce

Product Category Permalinks in WooCommerce – pfew that's a mouthful. And it sounds so boring and technical. I do occasionally get asked some questions about WooCommerce permalinks and a little understanding of how permalinks work in WooCommerce should explain why we create them that way.

Product Categories

It makes logical sense to sell a t-shirt and to categorize it under clothing. If each product is in one and only one category then you shouldn't have any permalink confusion. But what happens when you're selling a book like Zen and the Art of Motorcycle Maintenance? Should it go into the zen category or the motorcycle category?

Now things get a little tricky. Since this is the virtual world (unlike the library) we can put the product in both categories. With WooCommerce you can navigate to Zen and the Art of Motorcycle Maintenance book via either category since. Unfortunately search engines are a different beast…

Apple Permalink

The permalink for my Apple product which is made out of the category slug (food) and the product slug (apple).

One Permalink to Rule Them All

For search engines you want to have only one permalink. Otherwise you start running into issues with Google and duplicate content. So no matter how many categories your products are in WooCommerce only creates one permalink for the product.

If you take a look through the code you'll see we're using the standard WordPress get_the_terms function. What does this mean? It means that you might not be able to choose the zen category to use in your permalink structure for Zen and the Art of Motorcycle Maintenance. It's whichever result is returned by get_the_terms. You could get zen or you could get motorcycles. This could be a pain for users who are trying to optimize for certain keywords.

Filters to the Rescue

WordPress being what it is already has filters for this case. You can look into the get_the_terms filter in the get_the_terms function (yes they share the same name) and write your own filter to remove certain options from the function. Just remove any unwanted categories and you'll be left with one category which will create the permalink for your product.

This is a little complex so if you're not a developer I recommend hiring one to help you write this filter.

 

One thought on “Product Category Permalinks in WooCommerce

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.