parent
f5e2717b6f
commit
6050b204fc
|
@ -414,7 +414,7 @@ class WC_AJAX {
|
|||
do_action( 'woocommerce_ajax_added_to_cart', $product_id );
|
||||
|
||||
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
|
||||
wc_add_to_cart_message( $product_id );
|
||||
wc_add_to_cart_message( array( $product_id => $quantity ), true );
|
||||
}
|
||||
|
||||
// Return fragments
|
||||
|
|
|
@ -648,7 +648,7 @@ class WC_Form_Handler {
|
|||
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
|
||||
|
||||
if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity ) !== false ) {
|
||||
wc_add_to_cart_message( $product_id );
|
||||
wc_add_to_cart_message( array( $product_id => $quantity ), true );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -678,7 +678,7 @@ class WC_Form_Handler {
|
|||
|
||||
if ( $passed_validation && WC()->cart->add_to_cart( $item, $quantity ) !== false ) {
|
||||
$was_added_to_cart = true;
|
||||
$added_to_cart[] = $item;
|
||||
$added_to_cart[ $item ] = $quantity;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,7 +752,7 @@ class WC_Form_Handler {
|
|||
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations );
|
||||
|
||||
if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) !== false ) {
|
||||
wc_add_to_cart_message( $product_id );
|
||||
wc_add_to_cart_message( array( $product_id => $quantity ), true );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,21 +61,29 @@ function wc_load_persistent_cart( $user_login, $user ) {
|
|||
* Add to cart messages.
|
||||
*
|
||||
* @access public
|
||||
* @param int|array $product_id
|
||||
* @param int|array $products
|
||||
* @param bool $show_qty Should qty's be shown? Added in 2.6.0
|
||||
*/
|
||||
function wc_add_to_cart_message( $product_id ) {
|
||||
function wc_add_to_cart_message( $products, $show_qty = false ) {
|
||||
$titles = array();
|
||||
$count = 0;
|
||||
|
||||
if ( is_array( $product_id ) ) {
|
||||
foreach ( $product_id as $id ) {
|
||||
$titles[] = get_the_title( $id );
|
||||
}
|
||||
} else {
|
||||
$titles[] = get_the_title( $product_id );
|
||||
if ( ! is_array( $products ) ) {
|
||||
$products = array( $products );
|
||||
$show_qty = false;
|
||||
}
|
||||
|
||||
if ( ! $show_qty ) {
|
||||
$products = array_fill_keys( array_values( $products ), 1 );
|
||||
}
|
||||
|
||||
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.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $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 ) );
|
||||
|
||||
// Output success messages
|
||||
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
|
||||
|
@ -97,7 +105,7 @@ function wc_format_list_of_items( $items ) {
|
|||
$item_string = '';
|
||||
|
||||
foreach ( $items as $key => $item ) {
|
||||
$item_string .= sprintf( _x( '“%s”', 'Item name in quotes', 'woocommerce' ), strip_tags( $item ) );
|
||||
$item_string .= $item;
|
||||
|
||||
if ( $key + 2 === sizeof( $items ) ) {
|
||||
$item_string .= ' ' . __( 'and', 'woocommerce' ) . ' ';
|
||||
|
|
Loading…
Reference in New Issue