Woocommerce Storefront template-tags.php无法更改为storefront_cart_link()

Luk*_*ars 4 php wordpress storefront woocommerce

我正在使用WordPress 4.3.1,Woocommerce 2.4.7和主题店面1.5.1.

我想更改标题中的"site-header-cart",它显示购物车的当前价格以及购物车中商品的数量,仅显示商品数量:

<span class="amount">463,33&nbsp;€</span>
<span class="count">7 items</span>
Run Code Online (Sandbox Code Playgroud)

应该:

<span class="count">7</span>
Run Code Online (Sandbox Code Playgroud)

每当我对template-tags.php进行更改时,只会更改

<a class="cart-contents" ...>
...
</a>
Run Code Online (Sandbox Code Playgroud)

正在展示.每当我尝试更改href内部的内容时,将显示未更改的原件:

if ( ! function_exists( 'storefront_cart_link' ) ) {
    function storefront_cart_link() {
        ?>
            <a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
                <span class="count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) );?></span>
            </a>
        <?php
    }
}
Run Code Online (Sandbox Code Playgroud)

怎么回事,谁能帮帮我?

rub*_*ine 10

我遇到过同样的问题.事实是,您必须在购物车上进行操作,例如添加商品或清空购物车以使您的更改可见.另一种选择是像Loque描述的那样清除sessionStorage.

1.将代码添加到自定义functions.php中

if ( ! function_exists( 'storefront_cart_link' ) ) {
    function storefront_cart_link() {
        ?>
            <a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
                <span class="count"><?php echo WC()->cart->get_cart_contents_count();?></span>
            </a>
        <?php
    }
}
Run Code Online (Sandbox Code Playgroud)

2.在购物车上执行操作或清除控制台中的sessionStorage:

sessionStorage.removeItem('wc_fragments')
Run Code Online (Sandbox Code Playgroud)

3.刷新浏览器 - >非常重要

之前:

<span class="count">1 items</span>
Run Code Online (Sandbox Code Playgroud)

后:

<span class="count">1</span>
Run Code Online (Sandbox Code Playgroud)