Ad
How To Refresh Cart And Checkout In Every 5 Seconds In WooCommerce?
I am working on WordPress / WooCommerce
My requirement is when the customer is on the CART page, I want to refresh CART every 5 seconds, without page load.
For eg: If the customer has added 1 product to the cart and the price is ₹8.00
Later on, Admin changes the price for the product from ₹8.00 to ₹10.00
How can I show the latest price without page refresh?
I am using this code, but not working
(function( $ ) {
'use strict';
jQuery( document ).ready(function($) {
function refresh_fragments() {
console.log('fragments refreshed!');
$( document.body ).trigger( 'wc_fragments_refreshed' );
}
refresh_fragments();
setInterval(refresh_fragments, 5000);
});
})(jQuery);
Ad
Answer
Try the below code. instead of using the wc_fragments_refreshed
trigger, you can trigger the update cart button.
Cart refresh.
(function( $ ) {
'use strict';
jQuery( document ).ready(function($) {
function refresh_fragments() {
console.log('fragments refreshed!');
jQuery( "[name='update_cart']" ).removeAttr( 'disabled' );
jQuery( "[name='update_cart']" ).trigger( 'click' );
}
setInterval(refresh_fragments, 5000);
});
})(jQuery);
UPDATE as per OP request.
Checkout Refresh.
Use update_checkout
trigger.
(function( $ ) {
'use strict';
jQuery( document ).ready(function($) {
function refresh_fragments() {
$( document.body ).trigger( 'update_checkout' );
}
setInterval(refresh_fragments, 5000);
});
})(jQuery);
Ad
source: stackoverflow.com
Related Questions
- → CORS missmatch because of http
- → Building sitemap for 2 wordpress install under 1 domain
- → How to remove empty elements after class?(jQuery)
- → Get width of an element and apply to another relative to the first one?
- → How to remove caption p class from wordpress?
- → 301 Redirection from no-www to www in wordpress
- → Laravel 5 routing using prefix
- → WordPress - Header position Top, Left &Right
- → how to add rel=nofollow to some specific external links in wordpress
- → octobercms install error: database is not empty?
- → How to edit the index page of wordpress theme?
- → How to select a Post Type (Wordpress) to pass a filter in head?
- → What sort of URL structure should be used to display AMP HTML vs vanilla HTML
Ad