I use simple function to display WooCommerce cart in menu. However I can't resolve one issue. When I change the cart page URL in WooCommerce -> Settings -> Advanced -> Cart Page the cart URL is not updated. I guess that it has something deal with an Ajax function, but this the reference code from the official WooCommerce docs. When I add item to the cart the cart URL is updated. How to update cart URL without adding items?

My code:

    * Cart icon with total price and items count
    function deo_woocommerce_cart_icon() {
        <div class="nav__cart">
            <a class="nav__cart-url" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php echo esc_attr__( 'View your shopping cart', 'furosa' ); ?>">
                <span class="nav__cart-icon-holder">
                    <i class="ui-cart nav__cart-icon"></i>
                    <span class="nav__cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>

    * Show cart contents / total Ajax
    function deo_woocommerce_header_add_to_cart_fragment( $fragments ) {

        $fragments['.nav__cart-url'] = ob_get_clean();

        return $fragments;
    add_filter( 'woocommerce_add_to_cart_fragments', 'deo_woocommerce_header_add_to_cart_fragment' );

Found, that was a PHP cache bug. If I open page in a new tab, it updates the URL. But if I stay on the same page, the URL stays in the cache, no matter how many times you reload the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.