I create a function on my woocommerce theme to add multiple product to cart with single button.
function bulk_add_process() {
if ( ! is_admin() ) {
if ( isset( $_GET['bulk_add'] ) && $_GET['bulk_add'] ) {
$data = $_GET['data'];
foreach ($data as $id => $qty) {
$added = WC()->cart->add_to_cart( $id, $qty);
}
}
}
}
add_action( 'wp_loaded', 'bulk_add_process' );
My function work normally when there is no product on cart.
Example (I am adding 1 product A and 1 product B):
Initial => Cart: Empty
After Add to Cart => Cart: A:1, B:1
The problem is when I add same product for the second time, the amount of first product on cart didnt get updated.
Example (I am adding 1 product A and 1 product B again):
Initial => Cart: A:1, B:1
After Add to Cart => Cart: A:1, B:2
(Product A's amount didn't increased)
Is there any solution?