WordPress WooCommerce购物车函数本地正常AWS生产环境失效
WooCommerce购物车数据在AWS生产环境显示异常(本地正常)
我在购物车下拉菜单中展示商品总数量与总金额,相关功能在本地环境运行正常,但部署到AWS生产实例后全部失效,购物车数量和总价均显示为0。
测试过以下WooCommerce购物车相关方法,均在本地正常但生产环境无效:
WC()->cart->cart_contents_count WC()->cart->get_cart_contents_count() WC()->cart->get_total() WC()->cart->get_cart_total() WC()->cart->cart_contents_total WC()->cart->total
同时尝试了两段基于woocommerce_add_to_cart_fragments钩子的代码,同样本地正常、生产环境无效:
第一段代码
add_filter( 'woocommerce_add_to_cart_fragments', 'header_add_to_cart_fragment' ); function header_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); ?> <a class="cart-customlocation" id="from-function" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"> <?php echo sprintf(_n('%d item', '%d items', WC()->cart->cart_contents_count), WC()->cart->cart_contents_count);?> - <?php echo WC()->cart->get_total(); ?> </a> <?php $fragments['a.cart-customlocation'] = ob_get_clean(); return $fragments; }
第二段代码
add_filter( 'woocommerce_add_to_cart_fragments', 'header_add_to_cart_fragment' ); function header_add_to_cart_fragment( $fragments ) { global $woocommerce; ob_start(); ?> <a class="cart-customlocation" id="from-function" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"> <?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_total(); ?> </a> <?php $fragments['a.cart-customlocation'] = ob_get_clean(); return $fragments; }
内容的提问来源于stack exchange,提问作者MD TAREK HOSSEN
相关产品推荐
相关产品推荐

