admin管理员组

文章数量:1307484

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am using WC()->cart->add_to_cart($new_post_id); to add a product ,but this function does not adding for the first time when cart is empty.

If I add product using default add to cart button, Then after the above function works properly so can you please point out the issue .

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am using WC()->cart->add_to_cart($new_post_id); to add a product ,but this function does not adding for the first time when cart is empty.

If I add product using default add to cart button, Then after the above function works properly so can you please point out the issue .

Share Improve this question edited Jan 13, 2021 at 12:29 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Sep 15, 2017 at 8:26 owtowt 991 gold badge1 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Quantity is missing of the product try to use

WC()->cart->add_to_cart( $new_post_id , $qty );

where $qty is a number of items you want to add in the cart for a particular product. hope this will help you.
Thank you.

本文标签: phpAdd to cart function not working for first product when cart is empty