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

Related products being retailed together

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

// Remove categories and only use tags in WooCommerce related products - By Robin Scott of Silicon Dales see
add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );
view raw gistfile1.txt hosted with ❤ by GitHub

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

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

In this video, you can see I’ve connected together relevant toy products 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 Things like this for your Woo store

Book Silicon Dales – contact us here – and we can carry out work like this on your WooCommerce store to make it stand out from the crowd, become more useful, and, ultimately, make more sales (we don’t guarantee this last part, but our work sure can help!).

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

  1. Code is updated, as the previous version wasn’t working. Tested and works as of 28 Oct 2019.

  2. 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

  3. 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 🙂

  4. 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

Leave a Reply

Your email address will not be published. Required fields are marked *