Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Change WooCommerce 3.0+ “has been added to cart” message
function mytheme_custom_add_to_cart_message($message, $product_id = null) {
$titles[] = get_the_title( key($product_id));
$titles = array_filter( $titles );
$added_text = sprintf( _n( '%s has been added to cart.', '%s have been added to cart', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) ); //Change the message here
$message = sprintf( '%s <a href="%s" class="button">%s</a>',
esc_html( $added_text ),
esc_url( wc_get_page_permalink( 'checkout' ) ), // Change to esc_url( wc_get_page_permalink( 'cart' ) ), if you want users to go to cart
esc_html__( 'Pay Now', 'woocommerce' ));
return $message;
add_filter( 'wc_add_to_cart_message_html', 'mytheme_custom_add_to_cart_message', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.