Ajax每秒更新一次Woocommerce迷你购物车

时间:2018-11-13 09:34:04

标签: php ajax wordpress woocommerce minicart

我有一家本地网站,上有woocommerce和扁平小童主题。我创建了一个微型购物车,可以正常运行,并且添加了ajax代码以使其更新。

Ajax代码:

add_filter( 'woocommerce_add_to_cart_fragments', 'flatsome_add_to_cart_dropdown', 30, 1 );
function flatsome_add_to_cart_dropdown( $fragments ) {
    global $woocommerce;
    global $flatsome_opt;
    ob_start();
    ?>
    <div class="cart-inner">
        <a href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" class="cart-link">
            <strong class="cart-name hide-for-small"><?php _e('Cart', 'woocommerce'); ?></strong>   
            <span class="cart-price hide-for-small">/ <?php wc_cart_totals_order_total_html(); ?></span>
            <!-- cart icon -->
            <div class="cart-icon">
                <?php if ($flatsome_opt['custom_cart_icon']){ ?> 
                    <div class="custom-cart-inner">
                        <div class="custom-cart-count"><?php echo $woocommerce->cart->cart_contents_count; ?></div>
                        <img class="custom-cart-icon" alt="<?php _e('Cart', 'woocommerce'); ?>" src="<?php echo $flatsome_opt['custom_cart_icon']?>"/> 
                    </div><!-- .custom-cart-inner -->
                <?php } else { ?> 
                    <strong><?php echo $woocommerce->cart->cart_contents_count; ?></strong>             
                    <span class="cart-icon-handle"></span>
                <?php } ?>
            </div><!-- end cart icon -->
        </a>
        <div  class="nav-dropdown">
            <div id="mini-cart-content" class="nav-dropdown-inner widget_shopping_cart widget_shopping_cart_content">
                <?php                                    
                    if (sizeof($woocommerce->cart->cart_contents)>0) {
                        echo woocommerce_mini_cart();
                    } else {
                        echo '<p class="empty">'.__('No products in the cart.','woocommerce').'</p>';
                    }                     
                ?>                                                                        
            </div><!-- .nav-dropdown-inner -->
        </div><!-- .nav-dropdown -->
    </div><!-- .cart-inner -->

    <?php
    $fragments['.cart-inner'] = ob_get_clean();
    return $fragments;
}

我的实际标题迷你手推车的外观看起来相同。我面临的问题是,所有这些都可以正常工作,但仅在第二次更改时有效。因此,例如,当您将产品数量更改为15时,主购物车将更新,而小购物车则保持不变。然后,如果您再次将数量更改为50,则迷你购物车和主购物车都将更新。然后再次,如果您进行更改,则第二次没有任何反应。这可能是缓存问题,我已经尝试过禁用插件,但似乎无济于事。有人遇到过这样的事情吗?

注意:数量的变化和计数是由插件自定义的,那么这可能会引起问题吗?

0 个答案:

没有答案