I am trying to resolve how I can remove Product Variations (Attributes/Meta) from the Product/Item title specifically when sending automated emails through WooCommerce.
I have successfully accomplished removing these attributes from titles and listing them below in the Cart, Checkout, My Account Order History, Creating Invoices & Packing Slips (WooCommerce PDF Invoices & Packing Slips). However, when I send emails they remain (they also remain in the title on the Admin Order Details page which is annoying but not the end of the world).
Disclaimer, I am new to WooCommerce and learning how to properly apply filters.
From my research I feel confident that I need to adjust the woocommerce_order_item_name filter but I'm not exactly sure what I need to adjust specifically.
I found a similar article, but it was referring to a very specific set of conditions: WooCommerce - Remove variation from product title in order details and email
Current Code:
/* Woocommerce: Item Descriptions: Cart/Order - 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;
}
/* Woocommerce: Item Descriptions: Cart/Order - 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;
}
/* Woocommerce: Item Descriptions: Checkout page - 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;
}
/* Woocommerce: Item Descriptions: Checkout page - 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;
}
/* Woocommerce: Item Descriptions: Remove Attributes in Packing Slip & Invoice */
add_filter( 'wpo_wcpdf_order_item_data', 'wpo_wcpdf_remove_variation_from_product_title', 10, 3 );
function wpo_wcpdf_remove_variation_from_product_title( $item_data, $order, $template_type ) {
if ( !empty($item_data['product']) && $item_data['product']->is_type( 'variation' ) ) {
$item_data['name'] = $item_data['product']->get_title();
}
return $item_data;
}