Answer the question
In order to leave comments, you need to log in
Why does ajax continue to work with the previous object when changing the product?
Hello!
There is a woocommerce store . On the site page, each time I click the id="change" button, I replace one product with another and vice versa, which I set, as in the code below or through a shortcode.
When adding a product to the cart, a modal window pops up with the product, which signals that it has been added.
<?php echo do_shortcode( '[add_to_cart id="21"]' ); ?>
<div id="order-wrapper"><a href="shop/?add-to-cart=21" data-quantity="1" class="btn btn-primary product_type_simple add_to_cart_button ajax_add_to_cart order" data-product_id="21" aria-label="Добавить в корзину" rel="nofollow">Заказать</a></div>
<button id="change">Изменить</button>
$('.add_to_cart_button').on('click', function() {
$('#modal-cart').modal('show');
});
$('#change').on('click', function() {
var attr = $('.order').attr("data-product_id");
if (attr == "21") {
$('.order').attr("href", "shop/?add-to-cart=42");
$('.order').attr("data-product_id", "42");
//$( "#order-wrapper" ).empty();
//$( "#order-wrapper" ).append('<a href="shop/?add-to-cart=42" data-quantity="1" class="bt btn-primanry product_type_simple add_to_cart_button ajax_add_to_cart order" data-product_id="42" aria-label="Добавить в корзину" rel="nofollow">Заказать</a>' );
} else {
$('.order').attr("href", "shop/?add-to-cart=21");
$('.order').attr("data-product_id", "21");
//$( "#order-wrapper" ).empty();
//$( "#order-wrapper" ).append('<a href="shop/?add-to-cart=21" data-quantity="1" class="bt btn-primanry product_type_simple add_to_cart_button ajax_add_to_cart order" data-product_id="21" aria-label="Добавить в корзину" rel="nofollow">Заказать</a>' );
}
});
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