【问题标题】:Related Products only by Tags, Not by Categories in WooCommerce 3在 WooCommerce 3 中仅按标签而不是按类别相关产品
【发布时间】:2018-06-08 12:02:13
【问题描述】:

我试图得到相反的结果:Related Products only by categories, not by tags in WooCommerce 3

我想仅根据产品标签而不是按类别显示相关产品。

到目前为止,我的 function.php 在我的子主题下有这个:

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

但它不起作用。

非常感谢任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce tags categories


    【解决方案1】:

    在 woocommerce 版本 3.2.x 中,我首先测试了此代码以仅基于产品标签显示相关产品:

    add_filter( 'woocommerce_product_related_posts_relate_by_category', '__return_false' );
    

    对于您将使用的产品标签:

    add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_false' );
    

    代码在您的活动子主题(或活动主题)的functions.php 文件中。 完美运行。

    重要提示:要查看更改,请进入 WooCommerce > 状态 > 工具并在“WooCommerce 瞬态”中单击“清除瞬态”按钮来清除瞬态。

    您的代码也可以正常工作,所以有些东西正在制造麻烦。它可以是插件、您的主题或您制作的其他代码。

    【讨论】:

    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    相关资源
    最近更新 更多