0
votes

i am creating a custom button to add products to cart using add_to_cart($product_id, $quantity) function. It's working well for the single property but when I change product_id with another product id then it shows error.

$cart = $woocommerce->cart->add_to_cart($product_id, $quantity);

when I try same with different product_ids it stops working. any solution?

1
what is the error?A Shah
@AkshayShah it return false when I change product idHarman Cheema
What is the value of new $product_id that you change to? Does it really exist?Nerijus Masikonis
@NerijusMasikonis first time i used it with $product_id = 85 i work properly. Now when i change $product_id = 93 it return false. but for $product_id = 85 still working well and increase its quantity in cart. and yes both product_ids exist .Harman Cheema

1 Answers

0
votes

Okay, thanks for the help. Finally, the problem is solved. Actually, 93 product_id product is out of stock that's why it returns false. add_to_cart() function does not work with a product out of stock.