Остановить пользовательскую функцию. js - PullRequest
1 голос
/ 15 января 2020
Файл

my admin- ajax. php вызывает небольшую нагрузку на сервер и заканчивается запросом 400. Ive оттачивал на виновника, который, кажется, "action = wishlist_counter", вызванный woocommerce. Хотя корзина отключена, она все еще вызывает проблемы. Код, о котором идет речь, находится в моем файле пользовательских тем. js и выглядит следующим образом;

 /*************************************************************
WOOCOMMERCE  WISHLIST
*************************************************************/

function to_wishlist_count() {
    $.ajax({
        type: 'POST',
        url: to_ajaxurl,
        data: {action : 'wishlist_counter'},
        success:function(data) {
            $('.to-wishlist-number').html(data);
            if(parseInt(data) === 0 ) {
                $('.to-wishlist-counter').animate({top:'-100%'}, 0);
            } else {
                $('.to-wishlist-counter').animate({top:0}, 400);
            }
        }
    });
}

$(document).ready(function() {
    to_wishlist_count();
});

$(document).on('click', '.product-remove a', function() {
    setTimeout(function() { 
        to_wishlist_count();
    }, 1500);
});

$(document).on('click', '.add_to_wishlist', function(){
    var $this = $(this);
    var productAdded = $this.parents('li.product').find('h3').text();
    if (productAdded == '') {
        productAdded = $('h1').text();
    }
    $('.wishlist-notification .item-product').html('"'+productAdded+'"');
    $this.parents('li.product').find('.product-img-wrap div.loading').fadeIn(100);
    setTimeout(function(){
        $('.to-wishlist-number').html(parseInt($('.to-wishlist-number').html())+1);
        $this.parents('li.product').find('.product-img-wrap div.loading').fadeOut(100);
        $('#header .wishlist-notification').fadeIn(400);
        setTimeout(function(){
            to_wishlist_count();
            $('#header .wishlist-notification').fadeOut(400);
        },2250);
    },500);
});

})(jQuery);

Как лучше всего удалить этот код или прекратить его из-за подлых действий. Удалить его из файла? или, может быть, какая-то функция?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...