From 4119ae0d7fb838dd23d2f1aeae2af3f6dc0ee055 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 20 Apr 2015 12:29:01 +0100 Subject: [PATCH] Tweak wc_add_to_cart_message #7976 --- includes/wc-cart-functions.php | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 8cb0371f550..ef0aa92cea0 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -64,33 +64,26 @@ function wc_load_persistent_cart( $user_login, $user ) { * @param int|array $product_id */ function wc_add_to_cart_message( $product_id ) { + $titles = array(); if ( is_array( $product_id ) ) { - - $titles = array(); - foreach ( $product_id as $id ) { $titles[] = get_the_title( $id ); } - - $added_text = sprintf( __( 'Added %s to your cart.', 'woocommerce' ), wc_format_list_of_items( $titles ) ); - } else { - $added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) ); + $titles[] = get_the_title( $product_id ); } + $titles = array_filter( $titles ); + $added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) ); + // Output success messages - if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) : - - $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() ); - - $message = sprintf('%s %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text ); - - else : - - $message = sprintf('%s %s', wc_get_page_permalink( 'cart' ), __( 'View Cart', 'woocommerce' ), $added_text ); - - endif; + if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) { + $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() ); + $message = sprintf('%s %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text ); + } else { + $message = sprintf('%s %s', wc_get_page_permalink( 'cart' ), __( 'View Cart', 'woocommerce' ), $added_text ); + } wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) ); } @@ -102,7 +95,6 @@ function wc_add_to_cart_message( $product_id ) { */ function wc_format_list_of_items( $items ) { $item_string = ''; - $items = array_filter( $items ); foreach ( $items as $key => $item ) { $item_string .= sprintf( _x( '“%s“', 'Item name in quotes' ), $item );