Customize the Added to Cart Message

, , ,

So I ran into a request where the client was looking to have a Continue Shopping button after a product got added to the cart.  So in this example I used the wc_add_to_cart_message hook to add a continue shopping button below what normally got output.  You will also see that you can customize this so that you can output whatever you like based on the products ID number.  Like say you wanted to say that you may also be interested in this other product you can also provide a link to said product.

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 ) {
  switch ($product_id) {
  	case "1001":
  		$message .= "Customized message text for the product with ID number 1001.";
    		$message .= '<div style="clear:both;"> </div><div style="margin:10px 0 10px 0;"><a href="'.site_url() .'/shop/" class="checkout-button button alt wc-forward">Continue Shopping</a></div>';
  return $message;



Posted on

October 14, 2016

Submit a Comment

Your email address will not be published. Required fields are marked *