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 https://silicondales.com/tutorials/woocommerce/remove-categories-only-use-tags-related-products/
add_filter( 'woocommerce_get_related_product_cat_terms', 'sd_remove_related_product_categories', 10, 2 );
function sd_remove_related_product_categories( $terms_ids, $product_id ){
return array();
}
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!).

Leave a Reply

Your e-mail address will not be published. Required fields are marked *