[英]Hide variation info from cart item title in WooCommerce 3+
Ever since we upgraded to Woocommerce version 3 our order confirmations are showing huge titles that include the variation detail.自从我们升级到 Woocommerce 版本 3 以来,我们的订单确认显示了包含变化细节的巨大标题。 I don't like how it looks and it breaks some important functionalities in some custom-made plugins.
我不喜欢它的外观,它破坏了一些定制插件中的一些重要功能。
Reference: Order Name Showing Variations since update to WC version 3参考: 订单名称显示自更新至 WC 版本 3 以来的变化
There is a filter that can be used to disable this data displaying in the title called woocommerce_product_variation_title_include_attribute_name
from what I understand. woocommerce_product_variation_title_include_attribute_name
我所知,有一个过滤器可用于禁用名为woocommerce_product_variation_title_include_attribute_name
的标题中显示的数据。 But I have no idea where to apply the filter.但我不知道在哪里应用过滤器。
Is there a quick way to apply the filter to change it back to display as it did before?是否有一种快速的方法可以应用过滤器将其更改回以前的显示状态?
This filter should work returning a false
value for $should_include_attributes
first argument in woocommerce_product_variation_title_include_attributes
filter hook this way:此过滤器应该以这种方式为
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;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。
It should just work as you expect.它应该像你期望的那样工作。
Update: The shorter way is:更新:较短的方法是:
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。
just works too.也行得通。
A quick gotcha if you're using this filter to remove attributes from e-mail items.如果您使用此过滤器从电子邮件项目中删除属性,则有一个快速的问题。 It appears that once an item has been written to an order the properties of it will not change.
似乎一旦将项目写入订单,它的属性就不会改变。
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
As @freemason_17 pointed out, @LoicTheAztec's answer could potentially hide those details at other places as well so just to be sure I added a condition that would limit this to the cart page alone:正如@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 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.