Remove Attribute Values from Product Variation Title and Show Them on Separate Rows

Remove attribute values from product variation title and show them on separate rows

UPDATED

1) Since WooCommerce 3+, to remove attribute values from Product variation title and to display them in a separate row will need to use this 2 dedicated simple hooks (in checkout page).

  • Removing attribute values from Product variation title:
add_filter( 'woocommerce_product_variation_title_include_attributes', 'variation_title_not_include_attributes' );
function variation_title_not_include_attributes( $boolean ){
if ( ! is_cart() )
$boolean = false;
return $boolean;
}
  • Display Product variation attributes label and values in separate rows:
add_filter( 'woocommerce_is_attribute_in_product_name', 'remove_attribute_in_product_name' );
function remove_attribute_in_product_name( $boolean){
if ( ! is_cart() )
$boolean = false;
return $boolean;
}

2) Checkout page - Remove the quantity from the product title and add it back in a separate row.

  • Remove the quantity from the product title:
add_filter( 'woocommerce_checkout_cart_item_quantity', 'remove_product_variation_qty_from_title', 10, 3 );
function remove_product_variation_qty_from_title( $quantity_html, $cart_item, $cart_item_key ){
if ( $cart_item['data']->is_type('variation') && is_checkout() )
$quantity_html = '';

return $quantity_html;
}
  • Add back the cart item quantity in a separate row:
add_filter( 'woocommerce_get_item_data', 'filter_get_item_data', 10, 2 );
function filter_get_item_data( $item_data, $cart_item ) {

if ( $cart_item['data']->is_type('variation') && is_checkout() )
$item_data[] = array(
'key' => __('QTY'),
'display' => $cart_item['quantity']
);

return $item_data;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested in Woocommerce version 3+ and works. You should maybe need to make some styling changes…

Display variations attributes values as separate rows in Woocommerce cart / checkout

Try the following, that will display your product variations attributes as separated rows, below the cart item title:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
add_filter( 'woocommerce_is_attribute_in_product_name', '__return_false' );

Code goes in function.php file of your active child theme (or active theme). I hope it will work.


Related:

  • Remove attribute values from product variation title and show them on separate rows
  • Hide variation info from cart item title in WooCommerce 3+

Hide variation info from cart item title in WooCommerce 3+

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.

How to auto copy title into description field for all WooCommerce variation products?

Instead of copying the variation product name in the variation description, you can assign it to the description dynamically using this very simple hooked function:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
return $product->get_name();
}

Or you can also append it to the description using:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
return $description . $product->get_name();
}

Or prepend it with:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
return $product->get_name() . $description;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.


On some cases when products have been created since a long time, the attributes are not displayed in the product variation name… You will need to add the following line:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_true' );

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

Related:

  • How to display the variation name in Woocommerce Items
  • Remove attribute values from product variation title and show them on separate rows


Related Topics



Leave a reply



Submit