Woocommerce Related Products Code Snippets and Best Plugins

If you use  WooCommerce to have an online store with WordPress, you will see that by default the product page shows related products at the end of it.

We Can Customize Your Theme!

Need theme customization Services? We offer feature-rich custom theme customization, based on your business requirement..

View Service!

However, the default functionality of this behavior is quite limited and does not allow you any customization, automatically displaying related products based on the category and tags assigned to the product.

If you want to take advantage of this section on your product page, there are several options to do it, some through a plugin and others. If you prefer minimalism in terms of plugins and you are not afraid to touch code, with snippets that modify WooCommerce functions.

Woocommerce Related Products Code Snippets

Show related products only by the tags assigned to the product:

Where to put the code: functions.php

add_filter('woocommerce_product_related_posts_relate_by_tag', function() {
return false;

Show Related Products Only by the Categories Assigned to the product:

Where to put the code: functions.php

add_filter('woocommerce_product_related_posts_relate_by_tag', function() {
return false;

Number of Related Products and Columns

Where to put the code: functions.php

add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 4; // show 4 products
$args['columns'] = 2; // are displayed in columns two by two
return $args;

Remove all Related Products 

And finally, if what we want is that no type of related product is displayed, we will add a function to functions.php to remove the WooCommerce hook that displays it:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

Best Woocommerce Related Products Plugins

Related Products for WooCommerce

Related Products for WooCommerce is one of the best free Woocommerce plugins for related products. It is a classic plugin for this type of modification. It always seems to be better to opt for one whose developer or team keeps improving or adapting continuously.

This plugin definitely will help you bring customer attention and increase sales by showing related products.

With this plugin, you also can disable related products if you want. Sometimes we don’t want to show related products so it will help you in that case.

Product Recommendations

Product Recommendations is one of the best WooCommerce-related product plugins. Its effectiveness and accuracy of recommendation are just perfect.

This plugin was updated more recently and also has good ratings. But it works differently since what it does is enable a short code through which you can show the related products in the part of the web or product sheet that you prefer.

Being able to add ids of specific products, or related by category or tag, number of products to display, etc… and even the option of displaying them through a carousel.


Related products are one of the strategies to increase sales without any extra investment. There aren’t many Woocommerce related product plugins available since it’s a very straightforward topic to solve.

So I have mentioned some handy code snippets to customize your Woocommerce store with related products. By using these Woocommerce related product code snippets you can easily add or remove Woocommerce related products to your online store.

I hope this article helps you better understand Woocommerce related products. If you have any questions or suggestions, don’t hesitate to comment below.

Leave a Comment

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