Add woocommerce_add_to_cart_sold_individually_found_in_cart hook

Makes it easy for 3p code to change the condition that identifies whether a "sold individually" product is in the cart. For example, 3p code may use this hook to identify whether a product with the same ID already exists in the cart (instead of relying on finding the same hash/key).
This commit is contained in:
Manos Psychogyiopoulos 2017-03-24 10:41:27 +02:00
parent 39e1fd9fc3
commit 24a2ff1960
1 changed files with 3 additions and 3 deletions

View File

@ -904,10 +904,10 @@ class WC_Cart {
// Force quantity to 1 if sold individually and check for existing item in cart
if ( $product_data->is_sold_individually() ) {
$quantity = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data );
$in_cart_quantity = $cart_item_key ? $this->cart_contents[ $cart_item_key ]['quantity'] : 0;
$quantity = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data );
$found_in_cart = apply_filters( 'woocommerce_add_to_cart_sold_individually_found_in_cart', $cart_item_key && $this->cart_contents[ $cart_item_key ]['quantity'] > 0, $product_id, $variation_id, $cart_item_data, $cart_id );
if ( $in_cart_quantity > 0 ) {
if ( $found_in_cart ) {
/* translators: %s: product name */
throw new Exception( sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', wc_get_cart_url(), __( 'View cart', 'woocommerce' ), sprintf( __( 'You cannot add another "%s" to your cart.', 'woocommerce' ), $product_data->get_name() ) ) );
}