# Related Products by Tag Only

> Makes the related products section match products by shared tags instead of shared categories, for more precise suggestions.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, related-products, tags
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-related-by-tag-only/

## Code

```php
add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );
add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_true' );
```

## Notes

Products without tags will show no related products.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Related Products by Tag Only" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
