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

Hide variation info from cart item title in WooCommerce 3+

自从我们升级到 Woocommerce 版本 3 后,我们的订单确认显示了包含变体详细信息的巨大标题。我不喜欢它的外观,它破坏了某些 custom-made 插件中的一些重要功能。

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

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

有没有一种快速的方法来应用过滤器以将其改回显示之前的状态?

此过滤器应该可以为 woocommerce_product_variation_title_include_attributes 过滤器挂钩中的 $should_include_attributes 第一个参数返回 false 值,方法如下:

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 文件或任何插件文件。

也很管用。

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

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

正如@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 );

我用这个:

/* -------------------- Remove variation names from title ------------------- */
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
add_filter( 'woocommerce_is_attribute_in_product_name', '__return_false' );