Nick
Nick

Reputation: 14283

Woocommerce - Add to cart button on template

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

Answers (2)

tungd
tungd

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

sticksu
sticksu

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

Related Questions