4

我正在使用 WordPress 4.3.1、Woocommerce 2.4.7 和主题店面 1.5.1。

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

<span class="amount">463,33&nbsp;€&lt;/span>
<span class="count">7 items</span>

应该:

<span class="count">7</span>

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

<a class="cart-contents" ...>
...
</a>

正在显示。每当我尝试更改 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
    }
}

怎么回事,谁能帮帮我?

4

1 回答 1

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
    }
}

2.对购物车进行操作或在Console中清除sessionStorage:

sessionStorage.removeItem('wc_fragments')

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

前:

<span class="count">1 items</span>

后:

<span class="count">1</span>
于 2016-10-18T07:36:37.223 回答