Skip to main content
WooCommerce

Related Products in WooCommerce by Your Own Criteria

Are you tired of the default WooCommerce related products algorithm not quite meeting your needs? Do you wish to showcase related products that share specific characteristics, such as categories and brands, to enhance the shopping experience for your customers?

The Solution

To solve this problem, you can use a custom code snippet that allows you to customize the related products query to prioritize products that share the same categories and brands as the current product.

How It Works

The code snippet uses the woocommerce_related_products filter to modify the related products query. It first retrieves the product categories and brands associated with the current product. Then, it constructs a tax query to fetch related products that share the same categories and brands.

If no related products are found, the code falls back to parent categories, ensuring that you always display some related products. Additionally, it excludes the current product from the related products list to avoid duplication.

Benefits

  1. More Relevant Related Products: By prioritizing products that share the same categories and brands, you can increase the relevance of related products and enhance the shopping experience for your customers.
  2. Increased Sales: By showcasing more relevant related products, you can increase average order value and sales.
  3. Customizable: You can adjust the display limit and other parameters to suit your specific needs.

How to Install Custom Related Products Code

Add the code snippet to your WordPress site using one of two methods:

  1. functions.php file: Locate the file in wp-content/themes/your-theme and add the code at the end.
  2. Code Snippets plugin: Use the plugin to add and manage the code snippet.

That’s it! Clear your cache and check the related products section on your product pages. If you have any questions or need further assistance, feel free to ask.

Conclusion

This custom code snippet provides a powerful solution to streamline related products in WooCommerce by your own criteria. By prioritizing products that share the same categories and brands, you can create a more relevant and engaging shopping experience for your customers. Try it out today and watch your sales grow!

Need WooCommerce expertise? I offer custom solutions and expert guidance. Hire me and let’s grow your business together!