How to Remove Related Products in WooCommerce in 3 Easy Options

WooCommerce Remove Related Products in 3 Easy Options [Quick Guide] Are you looking for a quick and easy way to turn off related products in WooCommerce product pages? In this post, I will share with you a quick solution to remove related products on WooCommerce that you can implement in a theme or a plugin.

By default, WooCommerce displays related products based on the category on the product pages. There are times when this feature is not useful especially when you have a single product that is not in categories or you do not want for aesthetic purposes.

WooCommerce Remove Related Products

To stop the related products from showing up on your theme, you need to understand how to add a code snippet to your functions.php file. There are dozens of WooCommerce themes that come with related products display in the single product page like one shown in the image below:

How to Remove Related Products on WooCommerce Single Page

If you want to remove WooCommerce related products by adding a code snippet to your theme the following are the steps you should take:

Locate Functions.php Theme File

Step 1: First you need to locate the functions.php; this file is located in your theme files. This is a very sensitive file and you should always backup before editing it since if an error occurs your site is likely to break or have a white screen of death error. If your theme has a child theme you should use the functions.php file provided in the child theme instead of editing the parent theme functions.php file.

Code Snippets 3 Options

//Option #1 Using remove action

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

//Option # 2 Using a filter action

add_filter('woocommerce_product_related_posts_query', '__return_empty_array', 100);

// Option # 3 Using CSS

.related.products {

  display: none;

}

Step 2: Add one of the two code snippets shared above (either the remove_action or add_filter) the CSS can also be used by adding to the styles.css file or the customizer additional CSS and save the changes.

Reload your single product page to ascertain that your changes have been effective. If you have an error on your site you should copy back the functions.php backup file and start again with the first step.

Snippet Code Explanation

#1) The remove_action is the most effective since it is designed to remove the action hook that adds the WooCommerce related products to the single page.

#2) The filter also filters all the content that is displayed on the single page and for the WooCommerce related products query, it returns an empty array since the second parameter is set to __return_empty_array.

#3) The last is just plain CSS that hides the related products block from visibility using the CSS display property.

Wrapping up

Add either of the code snippets to your WooCommerce theme or if you are a WooCommerce plugin developer and want to hide the related products in your plugin, try out either of these snippets and let me know if it works.

Comments are closed.