使用“添加到购物车片段”更新WooCommerce中的颜色,购物车数量

时间:2019-10-07 05:23:55

标签: php wordpress woocommerce

我正在制作一个自定义主题,需要根据购物车状态更改购物车div背景颜色。 条件 如果购物车为空,则背景应显示为灰色,并且当购物车中的项目表示购物车计数大于0时,应显示为橙色背景色。

enter image description here

$ql_cart_wrap_color;

这里ql_cart_wrap_color_gray将类从ql_cart_wrap_color_orange更改为woocommerce_add_to_cart_fragments,这在添加到购物车产品时效果很好。但是,当我们从购物车中取出物品时,我的意思是购物车再次变空,再也不会变成灰色背景。

所以我现在使用function dynamic_header_add_to_cart_fragment_refresh( $fragments ) { ob_start(); ?> <?php $ql_cart_wrap_color = (WC()->cart->get_cart_contents_count() == 0 ) ? 'ql_cart_wrap_color_grey' : 'ql_cart_wrap_color_orange';?> <div class="ql_cart_wrap woo_amc_open_active <?php echo $ql_cart_wrap_color; ?>"> <button href="javascript:" class="ql_cart-btn"> <span class="count"><?php echo esc_html( WC()->cart->cart_contents_count );?></span> <span class="cart-header"></span> </button> </div> <?php $fragments['.ql_cart_wrap'] = ob_get_clean(); return $fragments; } add_filter( 'woocommerce_add_to_cart_fragments', 'dynamic_header_add_to_cart_fragment_refresh' ); 过滤器,它只有在添加到购物车时才起作用

conda create -y --name tensorflow python=3.6

是否有其他方法可以刷新页面而不刷新页面?

0 个答案:

没有答案