购物车为空时如何隐藏柜台? WordPress-woocommerce-supro主题
<a href="<?php echo esc_url( wc_get_cart_url() ) ?>" class="cart-contents" id="icon-cart-contents">
<?php echo wp_kses_post( $icon_cart ); ?>
<span class="label-item cart-label"><?php echo wp_kses( $cart_html, wp_kses_allowed_html( 'post' ) ); ?></span>
<span class="mini-cart-counter"><?php echo intval( $woocommerce->cart->cart_contents_count ); ?></span>
</a>
Tnx
答案 0 :(得分:2)
更新:将此代码添加到您的子主题的 functions.php
add_action( 'wp_head', 'x_hide_cart' );
function x_hide_cart(){
if ( WC()->cart->get_cart_contents_count() == 0 ) {
?>
<style type="text/css">.x-menu-item-woocommerce{display: none;}</style>
<?php
}
}
答案 1 :(得分:0)
有几种方法可以做到这一点,例如,我会将代码包装在if语句中
<?php
if ( $woocommerce->cart->cart_contents_count > 0 ) {
?>
<a href="<?php echo esc_url( wc_get_cart_url() ) ?>" class="cart-contents" id="icon-cart-contents">
<?php echo wp_kses_post( $icon_cart ); ?>
<span class="label-item cart-label"><?php echo wp_kses( $cart_html, wp_kses_allowed_html( 'post' ) ); ?></span>
<span class="mini-cart-counter"><?php echo intval( $woocommerce->cart->cart_contents_count ); ?></span>
</a>
<?php
}
?>