w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
WooCommerce add_to_cart Shortcode - Product already in Cart

Try this,

When the users clicks on the button you can check the current cart item with this code.

global $woocommerce;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key =>
$cart_item ) {

  if($cart_item['product_id'] == $your_product_id){
   //the item already added to the cart
 }
} 

This will iterate the all items in the cart also if you want to add a product forcefully to the cart just need this,

$woocommerce->cart->add_to_cart($product_id,$qty);

Hope its helps..





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.