WooCommerce: Add custom Add To Cart Message & Custom “Continue Shopping Link”

Add this code in function.php

 

<?php

/**

* Custom Add To Cart Messages

* Add this to your theme functions.php file

**/

add_filter( 'wc_add_to_cart_message', 'woocommrece_custom_add_to_cart_message' );

function woocommrece_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'));// Give the url, you want to redirect

 

$message = sprintf('<a href="%s">%s</a> %s', $return_to, __('Continue Shopping &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );

 

else :

 

$message = sprintf('<a href="%s">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );

 

endif;

 

return $message;

}

/* Custom Add To Cart Messages */

?>
Advertisements

14 thoughts on “WooCommerce: Add custom Add To Cart Message & Custom “Continue Shopping Link”

  1. hi, i need this on my cart page and don’t know much about how to apply this. which file name again and all of this code above?

  2. I want something like this : when user clicks on ‘add to cart’, it should display a message on the top ‘added to cart’ without page refresh. pls help me. thanks

  3. After reading this I can’t still figure out how to redirect users to the shop page when they click on the Continue Shopping button at the cart page. They get sent to the product page of the same purchase they just made when they add variable products to the cart. It does work for simple products. Help anyone?

  4. Thanks for the function. I’m desperately trying to pass an id an a data- attribute to the link with no success. Manually changing the html output seems not to work, or passing a variable such as $attributes = 'id="show_cart" data-target="open-cart"'; does not work either. Could anyone please tell me if this is even possible?

    Thanks in advance.

  5. Thanks for this.. giving it a test now to see if it is still relevant. I did notice there is a spelling error in the variable name “woocommrece_custom_add_to_cart_message” should be “woocommerce_custom_add_to_cart_message” . Needs to be updated in two places

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s