Categories

Thursday, March 28, 2024
#919814419350 therichposts@gmail.com
Woocommerce Hooks

WOOCOMMERCE HOOK : ADD EMPTY CART BUTTON TO CART PAGE

How to add download pdf link in woocommerce single product page?

WOOCOMMERCE HOOK : ADD EMPTY CART BUTTON TO CART PAGE

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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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