I have a variation called "China" on some of my products. The way WooCommerce works, is that inside the cart, order details and emails, the variations are being appended to the product title. I would like to have the word "China" removed from the title in the cart, checkout, order details and email.
Current Title: "Apple MacBook Pro 15 - China, 16GB Ram, 512GB SSD"
Required Title: "Apple MacBook Pro 15 - 16GB Ram, 512GB SSD"
I managed to remove it from the title when it's inside the cart and checkout page, using this code:
function remove_variation_from_product_title( $title, $cart_item, $cart_item_key ) {
$_product = $cart_item['data'];
if ( $_product->is_type( 'variation' ) ) {
$replace = array( 'China,', 'China' );
$title = str_replace( $replace, '', $title);
return apply_filters( 'woocommerce_product_variation_title', $title );
}
return $title;
}
add_filter( 'woocommerce_cart_item_name', 'remove_variation_from_product_title', 10, 3 );
But as you can see from the filter, it only removes it from the cart. Once the order is made, the full title with variations are being shown again in the order details page as well as in the email that is sent from the customer.
I did come across another filter called woocommerce_order_items_meta_display
, but failed to get anywhere with it.
Does anyone know how I could filter the product title across the entire store, and not just in the cart and checkout page?
Thanks.
Update:
Found the solution. woocommerce_order_item_name
did the trick. It also applies it to the email that is sent to the customer.
function remove_variation_from_product_title_order( $title, $item, $is_visible ) {
$_product = $item['data'];
$replace = array( 'China,', 'China' );
$title = str_replace( $replace, '', $title);
return apply_filters( 'woocommerce_product_variation_title', $title );
}
add_filter( 'woocommerce_order_item_name', 'remove_variation_from_product_title_order', 10, 3 );
woocommerce_update_order_item_meta
it will help – raju_odi