Home Woocommerce Hooks WOOCOMMERCE HOOK : ADD EMPTY CART BUTTON TO CART PAGE

WOOCOMMERCE HOOK : ADD EMPTY CART BUTTON TO CART PAGE

by therichpost
0 comment
woocommerce

Hello, welcome to therichpost.com. In this post, I will tell you WOOCOMMERCE HOOK : ADD EMPTY CART BUTTON TO CART PAGE. WordPress is the best cms and Woocommerce is the best Ecommerce plugin. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.

With woocommerce Empty cart button, we can easily delete all the products from our cart.

Here is the working hook for WOOCOMMERCE ADD EMPTY CART BUTTON TO CART PAGE and you need to add this into your theme’s functions.php file:

/* — WOOCOMMERCE: ADD EMPTY CART BUTTON TO CART PAGE — */
add_action(‘woocommerce_after_cart_contents’, ‘woocommerce_empty_cart_button’);
function woocommerce_empty_cart_button( $cart ) {global $woocommerce;$cart_url = $woocommerce->cart->get_cart_url();?>
<div class=”emptyCart”>
<?php
if(empty($_GET)) {?>
<a class=”button emptycart” href=”<?php echo $cart_url;?>?empty-cart”><?php _e(‘Empty Cart’,’wc-emptycart’); ?></a>
<?php } else {?>
<a class=”button emptycart” href=”<?php echo $cart_url;?>&clear-cart=empty-cart”><?php _e(‘Empty Cart’,’wc-emptycart’); ?></a>
<?php } ?>
</div>
<?php }
// check for empty-cart get param to clear the cart
add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
function woocommerce_clear_cart_url() {
global $woocommerce;

if ( isset( $_GET[’empty-cart’] ) ) {
$woocommerce->cart->empty_cart();
}
}

There are so many hooks in wordpress and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.