Skip to content

Instantly share code, notes, and snippets.

@andxbes
Created July 20, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andxbes/e22716d7bdc9a8bb7e89e03d5c57a6fc to your computer and use it in GitHub Desktop.
Save andxbes/e22716d7bdc9a8bb7e89e03d5c57a6fc to your computer and use it in GitHub Desktop.
Woo update cart
<?php
add_action('woocommerce_add_to_cart_fragments', function($fragments){
$count = WC()->cart->get_cart_contents_count();
ob_start(); ?>
<span class="cart-value" <?php echo ($count == 0) ? 'style="display:none;"' : ''; ?>><?php echo $count ?></span>
<?php $fragments['span.cart-value'] = ob_get_clean();
return $fragments;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment