Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

php - 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. 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

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. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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.

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.

just works too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...