I'm actually doing custom template for my client. My client want to have few specific products to show with their add to cart button on homepage.
On internet I didn't found the answer for this specific behavior of WooCommerce.
I know, basicly add to cart buttons on single pages are <button>
elements but I think for my use will be better use <a>
element, so I found how looks that construction of add to cart URL.
After this I picked IDs of products which client wants to offer on homepage and did this link: <a href="<?php echo 'https://betlive.cz/?add-to-cart='.get_the_ID().'&quantity=1'; ?>" class="add_to_cart_button btn btn-outline-primary btn-lg">Přidat do košíku</a>
But after applying this link I could not add product to the cart (I've got redirected and getting message that cart is empty) On this discussion on wordpress.org I found that I should add class: add_to_cart
to my button which I've done, after this I can successfully add product to cart if I'm logged in as admin, but when I try add any product from homepage in anonymous window through that button, I can't, I'm get redirected to the cart and cart is empty.
Do you have, please any ideas how to debug this stuff?
PS: get_the_ID()
is working for getting ID of products from my query, I think that query which I'm using to loop through products to show on homepage is right because the button works, but only if I'm logged in as admin.
On the site is not any active WP cache plugin, I've also tried deactivate Wordfence but it still not help, actually I'm using these plugins on the site: WooCommerce 8.5.2, Regenerate Thumbnails 3.1.6, WooCommerce Stripe Gateway 8.0.0 and Font Awesome 4.0.0