Answer the question
In order to leave comments, you need to log in
WooCommerce ajax?
Good afternoon, I'm learning to work with WP, I started to pick WooCommerce and I'm trying to attach it to my layout.
There is a page with goods and at the top I display a mini basket: prices / quantity / description.
The question is how can I change the data in it with the help Ajax?
of Now "в корзину"
I just hung the function on the button
<a href="/home/?add-to-cart=<?= $product->id ?>" data-quantity="1" class="product_type_simple add_to_cart_button ajax_add_to_cart product__button" data-product_id="<?= $product->id ?>" data-product_sku="" aria-label="Добавить "<?= $product->name ?>" в корзину" rel="nofollow">В корзину</a>
$('.ajax_add_to_cart').on('click', function(e){
e.preventDefault();
let $href = $(this).attr('href');
$.ajax({
type: "GET",
url: $href,
data: $href.split('?')[1]
}).done(function() {
console.log('done');
}).fail(function(){
console.log('error');
}).always(function() {
console.log('always');
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question