In woocommerce if you add an item in cart then the cart needs to be updated which happens only after you reload the page.
Write this code in your theme’s functions.php to refresh the cart using ajax without reloading the page.
[php]
<?php
// Cart contents are updated when products are added to the cart via AJAX (place it in functions.php)
add_filter( ‘woocommerce_add_to_cart_fragments’, ‘woocommerce_header_add_to_cart_fragment’ );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( ‘View your shopping cart’ ); ?>"><?php echo sprintf (_n( ‘%d item’, ‘%d items’, WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> – <?php echo WC()->cart->get_cart_total(); ?></a>
<?php
$fragments[‘a.cart-contents’] = ob_get_clean();
return $fragments;
}
?>
[/php]