Reputation: 14283
I am writing a template for my wordpress site.
The template loops trough woocommerce products and prints out some information (image, description, price and so on)
The issue I am facing is with the "add to cart" button.
This is the code I have:
<a href="/cart/?add-to-cart=<?php echo $loop->post->ID; ?>" rel="nofollow" data-product-id="<?php echo $loop->post->ID; ?>" class="btn btn-primary">Add to cart</a>
and I am trying to NOT redirect after the button is clicked.
I already have:
Enable AJAX add to cart buttons on archives
ticked as options, but I can't find how to not redirect after button is clicked.
Thanks for any help
Upvotes: 2
Views: 10553
Reputation: 14887
In add-to-cart.js
, the event is bind to button with add_to_cart_button
and ajax_add_to_cart
classes and the data-product_id
attribute.
Upvotes: 5
Reputation: 3738
Your href is "/cart/?add-to-cart=<?php echo $loop->post->ID; ?>"
which basicaly sais that you redirect to the cart page and add the product to the cart.
Try it like this href="?add-to-cart=<?php echo $loop->post->ID; ?>"
, it should keep you on the same page.
Upvotes: 4