Add Product Name to Add to Cart Message in WooCommerce

PHP

// Customize WooCommerce add to cart message
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 ) {
    // Get the title of the product that was added to the cart
    $product_title = get_the_title( $product_id );

    // Create a custom message using the product title
    $custom_message = sprintf( esc_html__( '%s has been added to your cart. Thank you for shopping!', 'woocommerce' ), $product_title );

    // Return the custom message
    return $custom_message;
}

Snippet Feedback

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

8 Views

Filters

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.