Remove Categories and only use Tags to show Related Products in WooCommerce

Below is a snippet of code, and a simple video explanation, which shows you how to edit the output of WooCommerce related products (shown at the bottom of the single product page) in order to not use product category and only use product tags as a mechanism for measuring “relatedness”.

The Code Snippet



NOTE – delete your transients or you won’t see this take effect! See the video below to hear about this… To delete transients, add plugin Transients Manager, and remove all transients using this. Then reload your page. Otherwise, it will look like nothing changed. You can also remove transients using WooCommerce > Status > Tools.

Where to put this code

Add this code into a child theme functions.php file, or a custom plugin, or (as in the video) a snippets plugin which holds only this piece of code.

The video guide

The video below explains how to use this code, what it does, and where to place it into your WooCommerce store.

In this video, toy products are shown connected together using the product tag “Cap Guns” – but this rule can apply nicely to most stores, to build more relevant “related” products. In case you’d like to check the output in real time, this is the product in the video.

Get more like this for your WooCommerce store

Book Silicon Dales – contact us here – and we can make your WooCommerce store stand out from the crowd, become more useful, and, ultimately, assist sales.

4 thoughts on “Remove Categories and only use Tags to show Related Products in WooCommerce”

  1. Hi, Thanks for your article,
    how could add two related products one with related tag and another with related categories?

    sorry for my English
    Thanks again

    Reply
  2. Thanks for your video! I tried the code and it didn’t work at all. Your video mentioned to delete transients, then I realized why it didn’t work and why I wasted a whole hour tried to alter this function with no effect 🙂

    Reply
  3. Thanks for this tip. I also had issues trying to have the code work. It might be very helpful to just edit your post and add a ‘point form’ How to do it! Many users who find this post might not necessarily have all the skills to understand and interpret what they need to do.

    Such as: steps to insert code
    1. Dashboard/Appearance/Woo Commerce/Single Product – make sure you have YES in Related Products
    2. Open an existing Product Page and view the related products Woo Commerce has inserted as Category default selection. Leave this browser tab open. (It;s a reference point)
    3. Download WP Plugin: Code Snippets
    4. Add a new snippet – code as supplied: add_filter( ‘woocommerce_product_related_posts_relate_by_category’, ‘__return_false’ );
    5. Then save and activate snippet
    5. Download WP Plugin: Transients Manager
    6. In Dashboard/Tools/Transient Mgr – open and run – Delete all non expiring transients
    6 Open the same Product page (as you did in point 1) refresh the page and see your new related items based on ‘tags’ not ‘categories’. I f it is still the same, you might have made a mistake!

    Cheers guys, thanks for a great alternative a s this is my first trail of Woo Commerce and my related products were ‘useless’ based on how I’d wanted to set up categories. You code saved the day!

    I hope the above points help newbies like myself. :):)

    Cheers Dennis

    Reply

Leave a comment

No links of any kind allowed in comments - if you add any links, your comment will automatically be deleted.