相关产品仅按类别分类,不按WooCommerce 3中的标签分类 [英] Related Products only by categories, not by tags in WooCommerce 3

查看:75
本文介绍了相关产品仅按类别分类,不按WooCommerce 3中的标签分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅尝试按类别显示WooCommerce中的相关产品。目前,WooCommerce使用标签和类别。

Trying to display related products in WooCommerce by categories only. At present WooCommerce uses tags and categories.

我们已经尝试实现以下功能,但随着时间的推移,我可能会因为WooCommerce方面的更新而停止工作。

We've tried implementing the following, but I'm guessing over time this will have stopped working perhaps owing to updates on WooCommerce side. It now no longer works in any theme we've tested.

add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_false' );


推荐答案


注意:该钩子现在再次可用。

NOTE: this hook is working again now.

一种功能替代:

查看相关的核心代码在842行,您有以下代码:

Looking at the related core code at line 842 you have this:

$tags_array = apply_filters( 'woocommerce_product_related_posts_relate_by_tag', true, $product_id ) ? apply_filters( 'woocommerce_get_related_product_tag_terms', wc_get_product_term_ids( $product_id, 'product_tag' ), $product_id ) : array();

您会注意到第二个过滤器挂钩: woocommerce_get_related_product_tag_terms 。因此,也许您可​​以尝试改用以下代码:

You will notice a second filter hook: woocommerce_get_related_product_tag_terms. So may be you can try to use instead this code:

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

代码会进入您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。

这已经过测试并且可以正常工作。

This is tested and works.

这篇关于相关产品仅按类别分类,不按WooCommerce 3中的标签分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆