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.
SHARED BY
8 Views