Every now and then, you come across an issue SO apparently simple you think you have to be stupid not see the answer and then it turns out – there isn’t an answer. This is my query.
Is there a way to have Related Products in WooCommerce only display products from a specific subcategory?
Here’s the issue.
I have a parent category, “MAKE UP” with 8 subcategories. As far as I can tell, the default Related Products will generate products randomly from both parent and child categories. This is crazy.
The parent category is only broadly related to its children, so showing “related” products from the parent category for products in the child category is unhelpful… to the point of being downright confusing.
I found a plugin called, WooCommerce Custom Related Products Pro. (Note the ‘Pro’. Yes, I paid for it.) It works, BUT there’s no global settings which means you have to manually add subcategories by product.
I only have 78 products in my shop so far but at around 1 min per product, that’s 1 hour & 18 minutes of work!
I used the excellent WP All Import plugin to do the heavy lifting of product amendments, but the WooCommerce Custom Related Products Pro fields don’t appear in the import.
It seems SO basic that I have to believe that I’m being stupid! Is there any way to set global parameters for Related Products?
Love to know!
First of all, you’re not alone. You’re not the first person to encounter this seemingly obvious need.
As you stated, WooCommerce determines whether products are “related” in three ways: Up-Sells, Cross-Sells, or by sharing the same tags or categories. And by “categories,” that can mean parent or child categories.
This page on the WooCommerce website contains the documentation on how to manually select products to up-sell or cross-sell.
But you’re asking how to automatically suggest Related Products from the same subcategory.
The first method is to use a plugin… which you tried. In addition to the plugin you suggested, there is a free version called, “WPC Custom Related Products for WooCommerce”. While the plugin gives you the ability to manually select related products, it doesn’t handle this automatically.
Honestly, if it only took you an hour or so to do this for your existing products, and then for each new product as you create them, that may be time well spent, and the easiest method of solving this problem!
But you can modify WooCommerce’s default behavior, using a bit of code. Here’s a function that someone wrote to do just this exact thing:
Please note that I have not tested this code snippet. If you have any issues using it, you’ll need to reach out to the author of the snippet for help.
You can add code like the above snippet to your child theme’s
functions.php file or via a plugin like the Code Snippets plugin. Avoid adding custom code directly to the
functions.php file in your parent theme, as it will be overwritten whenever you update the theme.
Finally, if you’re not comfortable editing the underlying code that powers your site, you can always hire a WooCommerce developer to tackle this minor change for you in less than an hour. You can start a conversation with an expert right here: https://www.wp101.com/help/
I hope this helps!