Tagged: , ,

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1006666

    Hi,
    I would like to add a remove button in the cart widget. Is this possible through some kind of hook?
    Thanks

    #1006844

    Hey wzshop,

    Have you looked into the following:

    Empty Cart Button for WooCommerce

    Best regards,
    Jordan Shannon

    #1007053

    Hi, thanks but how do i get that button in the cart widget (top/menu) ?
    Any hook i can use?

    #1007074

    Ehm not sure why no one mentioned this before, but this is an easy CSS fix. Enfold tends to hide the delete button.
    This fixed it:

    #top .dropdown_widget_cart ul.product_list_widget li a.remove{display: block;}

    However, when deleting a product the cart total is not updating… Any fix for that?

    • This reply was modified 5 years, 6 months ago by wzshop.
    #1007123

    Hi,

    This would require some code changes to the cart widget js script. Probably the easiest solution would be to trigger a page refresh as soon as the remove button is clicked. Try to add this code to the child theme functions.php:

    
    add_action('wp_footer', 'ava_custom_remove_cart_click');
    function ava_custom_remove_cart_click(){
    ?>
    <script>
    jQuery('#top .dropdown_widget_cart ul.product_list_widget li a.remove').click(function() {
    window.location.reload(true);
    });
    </script>
    <?php
    }
    

    Best regards,
    Peter

    #1007179

    Hi, thanks, but it is not reloading/refreshing.
    Any ideas?

    #1007367

    Hi wzshop,

    Can you give us a link to your site? so we can inspect and check further why the code isn’t working on your end.

    Best regards,
    Nikko

    #1007944

    See private content

    #1008029

    Hi!

    The script logic was more complex then I expected but now I’ve found a solution which updates the counter even without reloading the page. I added this code to your child theme functions.php:

    
    add_action('wp_footer', 'ava_custom_remove_cart_click');
    function ava_custom_remove_cart_click(){
    ?>
    <script>
    setInterval(function(){
    	var the_html		= jQuery('html'),
    	    cart			= jQuery('body').is('.woocommerce-cart'),
    		cart_counter	= jQuery('.cart_dropdown .av-cart-counter'),
    	    menu_cart		= jQuery('.cart_dropdown'),
    		counter			= 0;
    	
    	menu_cart.find('.cart_list li .quantity').each(function(){
    							counter += parseInt(jQuery(this).text(),10);
    						});		
    
    	if( counter === 0 )
    	{
    		cart_counter.removeClass('av-active-counter').text(counter); 
    		setTimeout( function() { the_html.removeClass('html_visible_cart'); }, 200);
    	}
    	else if( (cart_counter.length > 0 ) && ( counter > 0 ) )
    	{
    		setTimeout(function(){ 
    				cart_counter.addClass('av-active-counter').text(counter); 
    				the_html.addClass('html_visible_cart');
    					}, 10); 
    	}
    }, 1500);
    </script>
    <?php
    }
    

    Best regards,
    Peter

    #1008038

    Hi, thanks. That works.
    I found however that the function below also does the trick:

    //Update mini cart totals

    add_filter( 'woocommerce_add_to_cart_fragments', 'update_mini_cart_totals', 10, 1 ); 
    function update_mini_cart_totals( $fragments ) {
    	if (WC()->cart->get_cart_contents_count() !== 0 ) {
       $fragments['.av-cart-counter.av-active-counter'] = '<span class="av-cart-counter av-active-counter">'. WC()->cart->get_cart_contents_count() . '</span>';
    	} else {
        $fragments['.av-cart-counter.av-active-counter'] = ob_get_clean();
    	}
        return $fragments;
    	
    }
    #1008040

    Hi,

    Great! I’m glad you found a solution. Did you need further help, or shall we close?

    Best regards,
    Jordan Shannon

    #1008042

    You can close, though I would like to know what solutions is preferable and why.

    #1008057

    Hi,

    Probably your code is better because it does not require setIntval. However I tried to hook on woocommerce_add_to_cart_fragments before and the code didn’t work for me.

    Best regards,
    Peter

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.