-
AuthorPosts
-
September 6, 2018 at 3:51 pm #1006666
Hi,
I would like to add a remove button in the cart widget. Is this possible through some kind of hook?
ThanksSeptember 6, 2018 at 11:58 pm #1006844Hey wzshop,
Have you looked into the following:
Best regards,
Jordan ShannonSeptember 7, 2018 at 11:22 am #1007053Hi, thanks but how do i get that button in the cart widget (top/menu) ?
Any hook i can use?September 7, 2018 at 12:03 pm #1007074Ehm 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 6 years, 3 months ago by wzshop.
September 7, 2018 at 2:20 pm #1007123Hi,
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,
PeterSeptember 7, 2018 at 4:30 pm #1007179Hi, thanks, but it is not reloading/refreshing.
Any ideas?September 8, 2018 at 7:35 am #1007367Hi 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,
NikkoSeptember 10, 2018 at 3:11 pm #1007944See private content
September 10, 2018 at 7:18 pm #1008029Hi!
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,
PeterSeptember 10, 2018 at 7:28 pm #1008038Hi, 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; }
September 10, 2018 at 7:29 pm #1008040Hi,
Great! I’m glad you found a solution. Did you need further help, or shall we close?
Best regards,
Jordan ShannonSeptember 10, 2018 at 7:31 pm #1008042You can close, though I would like to know what solutions is preferable and why.
September 10, 2018 at 7:54 pm #1008057Hi,
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 -
AuthorPosts
- You must be logged in to reply to this topic.