Tweak wc_add_to_cart_message #7976
This commit is contained in:
parent
31104f6903
commit
4119ae0d7f
|
@ -64,33 +64,26 @@ function wc_load_persistent_cart( $user_login, $user ) {
|
||||||
* @param int|array $product_id
|
* @param int|array $product_id
|
||||||
*/
|
*/
|
||||||
function wc_add_to_cart_message( $product_id ) {
|
function wc_add_to_cart_message( $product_id ) {
|
||||||
|
$titles = array();
|
||||||
|
|
||||||
if ( is_array( $product_id ) ) {
|
if ( is_array( $product_id ) ) {
|
||||||
|
|
||||||
$titles = array();
|
|
||||||
|
|
||||||
foreach ( $product_id as $id ) {
|
foreach ( $product_id as $id ) {
|
||||||
$titles[] = get_the_title( $id );
|
$titles[] = get_the_title( $id );
|
||||||
}
|
}
|
||||||
|
|
||||||
$added_text = sprintf( __( 'Added %s to your cart.', 'woocommerce' ), wc_format_list_of_items( $titles ) );
|
|
||||||
|
|
||||||
} else {
|
} 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
|
// Output success messages
|
||||||
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
|
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() );
|
||||||
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
|
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
|
||||||
|
} else {
|
||||||
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
|
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_page_permalink( 'cart' ), __( 'View Cart', 'woocommerce' ), $added_text );
|
||||||
|
}
|
||||||
else :
|
|
||||||
|
|
||||||
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_page_permalink( 'cart' ), __( 'View Cart', 'woocommerce' ), $added_text );
|
|
||||||
|
|
||||||
endif;
|
|
||||||
|
|
||||||
wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );
|
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 ) {
|
function wc_format_list_of_items( $items ) {
|
||||||
$item_string = '';
|
$item_string = '';
|
||||||
$items = array_filter( $items );
|
|
||||||
|
|
||||||
foreach ( $items as $key => $item ) {
|
foreach ( $items as $key => $item ) {
|
||||||
$item_string .= sprintf( _x( '“%s“', 'Item name in quotes' ), $item );
|
$item_string .= sprintf( _x( '“%s“', 'Item name in quotes' ), $item );
|
||||||
|
|
Loading…
Reference in New Issue