0

Let say someone decides to buy my product and click on the buy now option and reached my checkout page. But for some reason he/she didn't buy it. But after sometime he/she made his mind to purchase the product but when they click on buy know button the product price get doubles because the product is added a second time in the cart. As i am not giving access to the cart page to my visitor so they can't modify there cart.

Is there anyway with which I can prevent the same product adding a second time in cart. I don't want the min maximum plugin because it doesn't prevent from adding same product multiple time. It just shows a notification that the max amount is 1.

I just don't want the same product to be addded twice in the cart no matter what.

I tried this code:

    add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
function woo_custom_add_to_cart( $cart_item_data ) {
    global $woocommerce;
    $woocommerce->cart->empty_cart();
    // Do nothing with the data and return
    return $cart_item_data;
}

But after adding it I am not able to add a second product into my cart. As I have added a order bump in my checkout page but when i tried to add it it replaced the main product.

1
  • 1
    Hiding cart wont prevent ?add-to-cart=25&quantity=999 so keep that in mind ;) Use the solution below to force only 1 qty per item
    – Snuffy
    Sep 14, 2021 at 7:45

1 Answer 1

0

You can force a single purchase of a given product from Edit Product > Product Data > Inventory > Sold Individually

No code needed

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.