I am trying to add an amount count down to my website header until free shipping is enabled.
Here is my code:
if ( ! function_exists( 'setup_free_shipping_counter' ) ) {
function setup_free_shipping_counter() {
ob_start();
?>
/* ... */
<p class="label-active"><span><?php echo get_shipping_cost_progress() ?></span> till free shipping</p>
/* ... */
<?php
return ob_get_clean();
}
}
add_shortcode('myshortcode', 'setup_free_shipping_counter');
function get_shipping_cost_progress() {
$min_amount = 50;
$current = WC()->cart->subtotal;
$progress = wc_price( $min_amount - $current );
return $progress;
}
The problem is that on cart Ajax events like Ajax add to cart, remove item from cart, change cart item quantity, the progress doesn't get updated.
How can I make my Shortcode get updated on woocommerce Ajax cart events?
If I reload page then Shortcode shows correct progress, but I need to make it to update dynamically on cart Ajax events.