添加产品后如何在整个网站上显示“添加到购物车”通知消息?

问题描述

当我单击“添加到购物车”时,将显示通知消息,但添加了购物车通知时仅显示主页产品,未在sin-gal产品页面或商店页面显示通知,因此如何启用我的整个网站。我的主题代码在此处,在此处进行更改以显示在整个网站上。

// add ajax cart loading
$(document).on('click','.add_to_cart_button',function(e) {
    var $this = $(this);
    if ($this.is('.product_type_simple')) {
        if ($this.attr('data-product_id')) {
            $this.addClass('product-adding');
        }
        //add to cart notifaction style 2
        if ($this.hasClass('viewcart-style-2')) {
            $('body').append('<div id="loading-mask"><div class="background-overlay"></div></div>');
            if (!$(this).closest('.product').find('.loader-container').length) {
                $(this).closest('.product').find('.product-image').append('<div class="loader-container"><div class="loader"><i class="porto-ajax-loader"></i></div></div>');
            }
            $(this).closest('.product').find('.loader-container').show();
        }
    }
});

// add to cart action
$(document).on('click','span.add_to_cart_button',function(e) {
    var $this = $(this);
    if ($this.is('.product_type_simple')) {
        if (!$this.attr('data-product_id')) {
            window.location.href = $this.attr('href');
        }
    } else {
        window.location.href = $this.attr('href');
    }
});

$('body').bind('added_to_cart',function() {
    $('ul.products li.product .added_to_cart').remove();
    initAjaxRemoveCartItem();
});

$(document.body).bind('wc_fragments_refreshed wc_fragments_loaded',function() {
    refreshCartFragment();
});

$(document).on('click','.product-image .viewcart,.after-loading-success-message .viewcart',function(e) {
    if (wc_add_to_cart_params.cart_url) {
        window.location.href = wc_add_to_cart_params.cart_url;
    }
    e.preventDefault();
});
var porto_product_add_cart_timer = null;
$(document).on('added_to_cart','body',function(event) {
    var $mc_item = $('#mini-cart .cart-items');
    if ($mc_item.length) {
        $mc_item.addClass('count-updating');
        setTimeout(function() {
            $mc_item.removeClass('count-updating');
        },1000);
    }
    $('.add_to_cart_button.product-adding').each(function() {
        var $link = $(this);
        $link.removeClass('product-adding');
        if ($link.hasClass('viewcart-style-1')) {
            $link.closest('.product').find('.viewcart').addClass('added');
        } else {
            //add to cart notifaction style 2
            $('body #loading-mask').remove();
            $link.closest('.product').find('.loader-container').hide();
            if ($link.closest('li.outofstock').length) {
                return;
            }
            $('.after-loading-success-message .product-name').text($link.closest('.product').find('.woocommerce-loop-product__title').text());
            $('.after-loading-success-message .msg-Box img').remove();
            if ($link.closest('.product').find('.product-image img').length) {
                $link.closest('.product').find('.product-image img').eq(0).clone().appendTo('.after-loading-success-message .msg-Box');
            }
            $('.after-loading-success-message').eq(0).stop().show();
            if (porto_product_add_cart_timer) {
                clearTimeout(porto_product_add_cart_timer);
            }
            porto_product_add_cart_timer = setTimeout(function() {
                $('.after-loading-success-message').eq(0).hide();
            },4000);
            $('.continue_shopping').click(function() {
                $('.after-loading-success-message').eq(0).fadeOut(200);
            });
        }
    });
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)