Custom “Added to Cart” Message

This snippet customizes the message displayed when a product is added to the cart, allowing for more personalized feedback.

PHP

function custom_add_to_cart_message( $message, $products ) {
    $titles = array();
    foreach ( $products as $product_id => $qty ) {
        $titles[] = get_the_title( $product_id );
    }
    return sprintf( '%s has been added to your cart. <a href="%s">View Cart</a>', implode( ', ', $titles ), wc_get_cart_url() );
}
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message', 10, 2 );

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.

1 Views

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.