2017 - 2019 - For Woocommerce 3+ (processing of multiple products has been added to the cart)
wc_add_to_cart_message_html filter hook wc_add_to_cart_message_html , the argument of the 2nd function was changed to $products (instead of $product_id ) ...
You can make changes to the code inside this connected function, as in this thread :
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message_html', 10, 2 ); function custom_add_to_cart_message_html( $message, $products ) { $titles = array(); $count = 0; foreach ( $products as $product_id => $qty ) { $titles[] = ( $qty > 1 ? absint( $qty ) . ' × ' : '' ) . sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( get_the_title( $product_id ) ) ); $count += $qty; } $titles = array_filter( $titles ); $added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', $count, 'woocommerce' ), wc_format_list_of_items( $titles ) ); // The custom message is just below $added_text = sprintf( _n("%s item has %s", "%s items have %s", $count, "woocommerce" ), $count, __("been added to your basket.", "woocommerce") ); // Output success messages if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) ); $message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue shopping', 'woocommerce' ), esc_html( $added_text ) ); } else { $message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) ); } return $message; }
Related topics (for Woocommerce 3+):
- Hide Woocommerce message added to cart
- Customize Cart Add Messages Based on Product Identifiers in WooCommerce 3
- Customize add to cart message in Woocommerce 3
LoicTheAztec
source share