S
S
Sergey2018-05-07 23:01:26
WordPress
Sergey, 2018-05-07 23:01:26

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="Добавить &quot;<?= $product->name ?>&quot; в корзину" 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');
    	});
  })

The data is sent, the product is added, but you need to somehow re-render the mini cart ...
Or am I doing some kind of game and there are more adequate ways?) Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question