jjzjj

php - Woocommerce Storefront template-tags.php 更改为 storefront_cart_link() 不可能

coder 2024-04-11 原文

我使用的是 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>

应该是:

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

这是怎么回事,有人能帮帮我吗?

最佳答案

我有同样的问题。事实是,您必须对购物车进行操作,例如添加商品或清空购物车,才能让更改可见。另一种选择是像 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。对购物车进行操作或在控制台清空sessionStorage:

sessionStorage.removeItem('wc_fragments')

<强>3。刷新浏览器 --> 非常重要

之前:

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

之后:

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

关于php - Woocommerce Storefront template-tags.php 更改为 storefront_cart_link() 不可能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33349417/

有关php - Woocommerce Storefront template-tags.php 更改为 storefront_cart_link() 不可能的更多相关文章

随机推荐