4
votes

I am using WordPress 4.3.1, Woocommerce 2.4.7 and the theme storefront 1.5.1.

I want to change the "site-header-cart" in the header, that displays the current price of the cart along the amount of items in the cart, to only show the number of items:

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

Should be:

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

Whenever I make changes to template-tags.php only changes outside of the

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

are being displayed. Whenever I try to change something inside the href the unchanged original will show up:

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

Whats going on, can anyone help me ?

1
Same here. All I know for now is that 1) When Javascript is disabled you see the changes in the template as expected; 2) There is an item in sessionStorage that holds the original template, which replaces the template you set.Loque
Have you tried clearing the sessionStorage item? In the console: sessionStorage.removeItem('wc_fragments')Loque

1 Answers

10
votes

I had the same Issue. The fact is, that you have to make a operation on the cart like add a item or empty the cart to get your changes visible. Another option is clearing the sessionStorage like Loque described.

1. Add code to your custom 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. Do a operation on the cart or clear the sessionStorage in Console:

sessionStorage.removeItem('wc_fragments')

3. Refresh your Browser --> very Important

Before:

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

After:

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