I would like to change the "Product has been added to your cart." text for variable products to include the variation.

For example if I added a size 7 Shoe to my cart it should say: "Shoe in Size 7 was added to your cart"

What do I have to edit to change this?

2 Answers 2

add_filter( 'wc_add_to_cart_message', 'my_add_to_cart_function', 10, 2 ); 

function my_add_to_cart_function( $message, $product_id ) { 
    $message = sprintf(esc_html__('« %s » has been added by to your cart.','woocommerce'), get_the_title( $product_id ) ); 
    return $message; 

The above code will help you to change the message. Since by knowing the hook wc_add_to_cart_message you can improve the code

  • Thanks! I've seen that code online but I'm not sure how to incorporate the product variation.
    – harvey
    Commented Mar 15, 2018 at 4:50
  • 1
    Will update answer for that soon. @harvey
    – melvin
    Commented Mar 15, 2018 at 4:51
 add_filter( 'wc_add_to_cart_message', 'custom_wc_add_to_cart_message', 10, 2 ); 

 function custom_wc_add_to_cart_message( $message, $product_id ) { 

 $message = sprintf( '%s has been added to your selection.', get_the_title( $product_id ) ); 

 return $message; 


Hope this will help you:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.