When add_to_cart is called, ensure the correct product_id is set for variations. Closes #4650

This commit is contained in:
Mike Jolley 2014-02-12 13:05:20 +00:00 committed by Coen Jacobs
parent 3e38d1ff17
commit d3dab23b75
1 changed files with 15 additions and 6 deletions

View File

@ -753,7 +753,9 @@ class WC_Cart {
*/
public function add_to_cart( $product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array() ) {
if ( $quantity <= 0 ) return false;
if ( $quantity <= 0 ) {
return false;
}
// Load cart item data - may be added by other plugins
$cart_item_data = (array) apply_filters( 'woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id );
@ -764,6 +766,13 @@ class WC_Cart {
// See if this product and its options is already in the cart
$cart_item_key = $this->find_product_in_cart( $cart_id );
// Ensure we don't add a variation to the cart directly by variation ID
if ( 'product_variation' == get_post_type( $product_id ) ) {
$variation_id = $product_id;
$product_id = wp_get_post_parent_id( $variation_id );
}
// Get the product
$product_data = get_product( $variation_id ? $variation_id : $product_id );
if ( ! $product_data )