简体   繁体   English

在 WooCommerce 3 中仅按标签相关产品,而不是按类别

[英]Related Products only by Tags, Not by Categories in WooCommerce 3

I try to get the opposite of: Related Products only by categories, not by tags in WooCommerce 3我试图反其道而行之: 仅按类别而不是 WooCommerce 3 中的标签的相关产品

I would like to show related products based only on product Tags, and Not by categories.我想仅根据产品标签显示相关产品,而不是按类别显示。

So far I have this in my function.php under my child theme:到目前为止,我在我的子主题下的function.php有这个:

add_filter( 'woocommerce_get_related_product_cat_terms', function( $term_ids, $product_id ){
    return array();
}, 10, 2 );

But it doesn't work.但它不起作用。

Any help is greatly appreciated.任何帮助是极大的赞赏。

In woocommerce version 3.2.x, I have tested first this code to only show related products based on product tags only:在woocommerce 3.2.x版本中,我首先测试了这段代码,只显示基于产品标签的相关产品:

add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );

For product tags you will use:对于产品标签,您将使用:

add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_false' );

Code goes in functions.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 functions.php 文件中。 It works perfectly.它完美地工作。

Important: To see changes, clear transients by going in WooCommerce > Status > tools and in "WooCommerce transients" click on "Clear transients" button.重要提示:要查看更改,请通过进入 WooCommerce > 状态 > 工具并在“WooCommerce 瞬变”中单击“清除瞬变”按钮来清除瞬变。

Your code works too, so there is something that is making trouble.你的代码也能工作,所以有一些事情在制造麻烦。 It can be a plugin, your theme or some other code made by you.它可以是插件、您的主题或您制作的其他一些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM