Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce Storefront template-tags.php changes to storefront_cart_link() not possible

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 ?

like image 575
Lukars Avatar asked Dec 24 '22 13:12

Lukars


1 Answers

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>
like image 141
rubeonline Avatar answered Jan 14 '23 13:01

rubeonline