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' );