【问题标题】:Hide counter on cart Wordpress在购物车 Wordpress 上隐藏计数器
【发布时间】:2020-08-28 06:44:08
【问题描述】:

购物车为空时如何隐藏柜台? 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

【问题讨论】:

    标签: php wordpress woocommerce wordpress-theming cart


    【解决方案1】:

    更新:将此代码添加到您的子主题的 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
        }
    }
    

    【讨论】:

    • 我是否需要更改代码的任何部分,因为不起作用...?
    • 您是否在子主题中进行了编辑?并且您没有更改项目类别?
    猜你喜欢
    • 1970-01-01
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 2020-06-06
    • 2013-05-07
    • 2014-07-28
    • 1970-01-01
    相关资源
    最近更新 更多