In this tutorial we’ll learn how to edit added to cart message in Woocommerce. We can achieve this b using one of Woocommerce’s filters.
Here is the default message being displayed when we add a product to cart.
Now I want to change this message with my custom message. To do so add the following lines of code at the end of functions.php file of your theme.
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' ); function custom_add_to_cart_message() { global $woocommerce; // Output success messages if (get_option('woocommerce_cart_redirect_after_add')=='yes') : $return_to = get_permalink(woocommerce_get_page_id('shop')); $message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') ); else : $message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') ); endif; return $message; } function your_woo_ajax_solution( $translation, $text, $domain ) { if ( $domain == 'woocommerce' ) { // your domain name if ( $text == 'View Cart' ) { // current text that shows $translation = 'Product successfully added to your cart.'; // The text that you would like to show } } return $translation; } add_filter( 'gettext', 'your_woo_ajax_solution', 10, 3 );
Add the Above code to the functions.php File.
If your shop is using ajax to add products to cart , then use the below function with filter else you can use above function with filter.
Now, after saving the file and refreshing the page when you add a product to cart you will get the custom message that you just set in function.php file.
Hi, is that possible with variable products also?