Home › Forums › Basel support forum › WC Minicart not updating – how to fix?
WC Minicart not updating – how to fix?
- This topic has 3 replies, 3 voices, and was last updated 3 years, 10 months ago by Artem Temos.
-
AuthorPosts
-
June 21, 2020 at 4:58 pm #205198
oleg_dmitrievParticipantHi guys, thank you for the very powerful theme. Can you please help, how can I fix this:
1) Minicart widget (in the Header): quantity and Subtotal amount are not updating automatically when product quantity is added or subtracted. https://ibb.co/QpWvCPk
I think the AJAX is not triggering the update. When I refresh the page, quantity and value in the Minicart changes. But not until I refresh. Can you sugges what code I can use to fix this?
2) After user added products into the Cart, on some pages, the Minicart is showing zero quantity, and zero value, on others it will show the correct quantity and value.
I think there should be a code to force update the Minicart – can you please help?
June 21, 2020 at 9:47 pm #205233
Elise NoromitMemberHello,
Have you checked how it works with the disabled plugins? If you have not, please check without plugins.
Best Regards
June 23, 2020 at 10:45 pm #205887
oleg_dmitrievParticipantElise,
Ok, so I fixed this, sharing with you in case it’s useful to improve Basel.
So, I had two issues: (1) the WP Rocket plugin compatibvility – it caches the Minicart values – so if you move from one page to the next, the value in the Minicart was lost. (2) To improve speed I disabled WooCommerce Cart Fragments JS and it broke down the Minicart updating. But Cart Fragments increases load time by 0.5s, so it’s best practice to disable it.
Solution:
1) in WP Rocket, there is a setting in WP Rocket > Never Cache Cookies: woocommerce_items_in_cart
This stops the Minicart from caching so it transfers from one page to next.
2) I realised the Minicart updating without the WooCommerce Cart Fragments.– – – First, snippet to disable cart fragments – – –
add_action( ‘wp_enqueue_scripts’, ‘ca_disable_woocommerce_cart_fragments’, 11 );
function ca_disable_woocommerce_cart_fragments() {
wp_dequeue_script( ‘wc-cart-fragments’ );
}– – – Second, snippet to autoupdate both cart and minicart on quantity change – – –
add_action( ‘wp_footer’, ‘cart_update’ );
function cart_update() {
if (is_cart()) { ?>
<script type=”text/javascript”>
var timeout, count;
jQuery(‘div.woocommerce’).on(‘change’, ‘input.qty’, function(){
if(timeout != undefined){
clearTimeout(timeout);
}
timeout = setTimeout(function() {
jQuery(“[name=’update_cart’]”).trigger(“click”);
setTimeout(function() {
var count = 0,
price = 0.0;
jQuery(‘td.product-subtotal .woocommerce-Price-amount.amount’).each(function(index, value) {
price = price + parseFloat(jQuery(value).text().substr(1));
});
jQuery(‘.basel-cart-subtotal .woocommerce-Price-amount.amount’).html(
jQuery(‘td.product-subtotal .woocommerce-Price-amount.amount’).first().text()[0] + price.toFixed(2)
);jQuery(‘.input-text.qty.text’).each(function(index, value) {
count = count + parseInt(value.value);
});
jQuery(‘.basel-cart-number’).html(count);}, 3000);
}, 1000);});
</script>
<?php
}
}
– – –June 24, 2020 at 6:23 am #205947
Artem TemosKeymasterHello,
We are glad that you sorted it out and posted your solution here.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register