Home Forums WoodMart support forum Changing Header cart-number to show when count > 0

Changing Header cart-number to show when count > 0

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #237011

    harryf98
    Participant

    Hello,

    I added this code to my functions.php of the Child Theme.
    I added it to this hook woocommerce_add_to_cart but when I add products to the cart it loads forever till I refresh the page.

    My Code:

    
    // Changing Header cart-number to show when count > 0
    function woodmart_cart_count() {
    	  $count = WC()->cart->get_cart_contents_count();
    	  if($count) { ?>
    		<span class="woodmart-cart-number"><?php echo esc_html($count); ?> <span><?php echo esc_html( _n( 'item', 'items', $count, 'woodmart' ) ); ?></span></span>
    <?php }
    }
    // add_action('woocommerce_add_to_cart', 'woodmart_cart_count');
    // add_action('woocommerce_add_to_cart', 'woodmart_cart_count',10);
    

    Kind Regards,
    Harry

    #237029

    Artem Temos
    Keymaster

    Hello,

    Sorry, but it is not an official code and we don’t provide support for such additional customizations.

    Kind Regards

    #237036

    harryf98
    Participant

    Hello,

    but I just added an if statement to the default woodmart_cart_count() which works fine.
    My problem was with the hook and if you know if I can use another one.

    Thank you anyways

    #237047

    Artem Temos
    Keymaster

    Yes, but when you add something to the cart, it calls this function with AJAX and the script expects some HTML to be returned. So by customizing this code you break other parts of the theme.

Viewing 4 posts - 1 through 4 (of 4 total)