It can happen that the shopping cart does not update immediately when you add products. This is due to the transmission of the products to the shopping cart via Ajax. So that this happens safely, there is this code.
if (!function_exists( 'evolution_header_add_to_cart_fragment' ) ) :
/**
* Ensure cart contents update when products are added to the cart via AJAX
*
* @add_filter woocommerce_add_to_cart_fragments
*/
function evolution_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php esc_html__( 'Deinen Warenkorb anzeigen', 'evolution' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items','evolution', 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;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'evolution_header_add_to_cart_fragment' );
endif;