$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce Cart URL bug|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce Cart URL bug

matteradmin7PV0评论

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:

<?php
    /**
    * 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>
                </span>
            </a>
        </div>
        <?php
    }

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

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

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

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:

<?php
    /**
    * 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>
                </span>
            </a>
        </div>
        <?php
    }

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

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

        return $fragments;
    }
    add_filter( 'woocommerce_add_to_cart_fragments', 'deo_woocommerce_header_add_to_cart_fragment' );
Share Improve this question edited Oct 22, 2018 at 9:32 Alexander asked Oct 22, 2018 at 7:23 AlexanderAlexander 1531 gold badge2 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far