WooCommerce : Add same product to cart twice instead of changing quantity in Cart Page.

In some of cases, We like to have product in WooCommerce added in the cart as separate items and not as the same item with the changed quantity. We can do that with pasting the code To the functions.php of theme.

Example :

This Is Done Basically In Two Steps:

Step 1: Split product quantities into multiple cart items.

function AddNewProductInsteadChangeQuantity( $cart_item_data, $product_id ) {
  $distinctive_cart_item_key = md5( microtime() . rand() );
  $cart_item_data['distinctive_key'] = $distinctive_cart_item_key;
  return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'AddNewProductInsteadChangeQuantity', 11, 2 );

Step 2: Force add to cart quantity to 1 and disable +- quantity input .Product can still be added multiple times to cart

add_filter( 'woocommerce_is_sold_individually', '__return_true' );

null

In This Hooks Basically, when we are adding a new product to cart ,we have added a unique key to each cart item meta. that’s why the same product become distinct product each time.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top