Allow extensions to run core WC cart handlers
Rather than determining how to handle a product being added to the cart based on its type, create a handler flag which extensions can set in order to run core WC handlers for different product types.
This commit is contained in:
parent
80b4ef14c9
commit
bd78ca6eec
|
@ -281,9 +281,10 @@ function woocommerce_add_to_cart_action( $url = false ) {
|
|||
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
|
||||
$was_added_to_cart = false;
|
||||
$adding_to_cart = get_product( $product_id );
|
||||
$add_to_cart_handler = apply_filters( 'woocommerce_add_to_cart_handler', $adding_to_cart->product_type, $adding_to_cart );
|
||||
|
||||
// Variable product handling
|
||||
if ( $adding_to_cart->is_type( 'variable' ) ) {
|
||||
if ( 'variable' === $add_to_cart_handler ) {
|
||||
|
||||
$variation_id = empty( $_REQUEST['variation_id'] ) ? '' : absint( $_REQUEST['variation_id'] );
|
||||
$quantity = empty( $_REQUEST['quantity'] ) ? 1 : apply_filters( 'woocommerce_stock_amount', $_REQUEST['quantity'] );
|
||||
|
@ -345,7 +346,7 @@ function woocommerce_add_to_cart_action( $url = false ) {
|
|||
}
|
||||
|
||||
// Grouped Products
|
||||
} elseif ( $adding_to_cart->is_type( 'grouped' ) ) {
|
||||
} elseif ( 'grouped' === $add_to_cart_handler ) {
|
||||
|
||||
if ( ! empty( $_REQUEST['quantity'] ) && is_array( $_REQUEST['quantity'] ) ) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue