admin管理员组文章数量:1130349
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
1 Answer
Reset to default 0Found, 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.
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
1 Answer
Reset to default 0Found, 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.
本文标签: WooCommerce Cart URL bug
版权声明:本文标题:WooCommerce Cart URL bug 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749180949a2328596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论