Woocommerce Ajax的逻辑添加到购物车代码以更新购物车

时间:2018-07-24 12:04:45

标签: ajax cart

在Woocommerce的add-to-cart.js文件中,触发added_to_cart事件时,将执行以下代码:

/**
 * Update cart page elements after add to cart events.
 */
AddToCartHandler.prototype.updateCartPage = function() {
    var page = window.location.toString().replace( 'add-to-cart', 'added-to-cart' );


    $( '.shop_table.cart' ).load( page + ' .shop_table.cart:eq(0) > *', function() {
        $( '.shop_table.cart' ).stop( true ).css( 'opacity', '1' ).unblock();
        $( document.body ).trigger( 'cart_page_refreshed' );
    });

    $( '.cart_totals' ).load( page + ' .cart_totals:eq(0) > *', function() {
        $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock();
        $( document.body ).trigger( 'cart_totals_refreshed' );
    });
};

我认为这段代码是在这里更新购物车页面元素的,在$( '.shop_table.cart' )$( '.shop_table.cart' )元素中加载购物车页面的新值...

但是我仍然不明白为什么page的值是window.location.toString().replace( 'add-to-cart', 'added-to-cart' );

实际上,当我们通过Ajax将商品添加到购物车时,window.location保持不变(即https://example.com/shop),所以为什么它应该是https://example.com/shop/?add-to-cart=10之类的东西,这有什么意义? location.windowhttps://example.com/shop/?added-to-cart=10的变化?

0 个答案:

没有答案