I have made a shortcode to display the amount of price needed for free shipping, when the customer reach the amount of 400 or more, the messege replaced by another messege.
I wan't this shortcode to be updated dynamically, without page refresh, same as the cart icon, that when user adds a product to cart the number of products in cart is changing automatically. My guess is that I need an ajax function, the question is how?
Please, can someone help me with that, my knowlage is basic but any help would be appreciated.
the shortcode:
add_shortcode( 'woocommerce_free_shipping_notice', 'free_shipping_cart_notice' );
function free_shipping_cart_notice() {
$min_amount = 400;
$current = WC()->cart->subtotal;
if ( $current < $min_amount ) {
echo '<p class="free-shipping-msg">you need ' . wc_price( $min_amount - $current ) . ' more to get free shipping</p>';
}
else if ($current > $min_amount ) {
echo '<p class="free-shipping-msg">you are now have a free shipping for current order.</p>';
}
}