隐藏WooCommerce 3+中购物车商品标题的变体信息

时间:2017-06-30 06:29:14

标签: php wordpress woocommerce product variations

自从我们升级到Woocommerce第3版以来,我们的订单确认显示了包含变化细节的大量标题。我不喜欢它看起来如何,它打破了一些定制插件的一些重要功能。

参考:Order Name Showing Variations since update to WC version 3

根据我的理解,有一个过滤器可用于禁用显示在名为 woocommerce_product_variation_title_include_attribute_name 的标题中的数据。但我不知道在哪里应用过滤器。

是否有一种快速方法可以应用过滤器将其更改为显示为之前的显示?

3 个答案:

答案 0 :(得分:13)

此过滤器应该可以在woocommerce_product_variation_title_include_attributes过滤器钩子中以false第一个参数返回$should_include_attributes值:

add_filter( 'woocommerce_product_variation_title_include_attributes', 'custom_product_variation_title', 10, 2 );
function custom_product_variation_title($should_include_attributes, $product){
    $should_include_attributes = false;
    return $should_include_attributes;
}

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

它应该像你期望的那样工作。

更新:更短的方式是:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

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

也适用。

答案 1 :(得分:2)

如果您正在使用此过滤器从电子邮件项目中删除属性,这将是一个快速的陷阱。似乎一旦将项目写入订单,它的属性就不会改变。

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

答案 2 :(得分:0)

正如@ freemason_17所指出的那样,@ LoicTheAztec的答案也可能会在其他地方隐藏这些详细信息,因此,请确保我添加了一个条件,将其限制在购物车页面之内:

function custom_product_variation_title($should_include_attributes, $product){
    if(is_cart()) {
        $should_include_attributes = false;
        return $should_include_attributes;
    }
}
add_filter( 'woocommerce_product_variation_title_include_attributes', 'custom_product_variation_title', 10, 2 );
相关问题