Hide and Remove Add to Cart Buttons in WooCommerce

A lot of people are using WooCommerce to build their online shop nowadays but I’m sure not all of them are really using the shopping cart functionality in WooCommerce.

If you are one of them and are are curious how to disable or remove the Add to Cart button from WooCommerce products, we’re going to provide you with a little snippets.

As always, add this code to your theme’s functions.php file.

// Remove shoopping cart
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');

Hide for Non Administrator Role

If you want to disable the Add to Cart button only for non-admin users, you use this instead:

// Remove shopping cart for non-admin users / normal site visitors
if ( ! current_user_can( 'administrator' ) ) {
 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
 remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}

Remove From Certain Product Category

This below snippet will be useful if you want to remove the add to cart button from certain product category.

// Remove the add to cart button on certain products
add_action('wp', 'risbl_hide_add_to_cart_category' );   
function QL_remove_add_to_cart_from_category(){ 
  if( is_product_category( 'category-name' ) ) { // you should replace category-name with your product category slug
    remove_action( 'woocommerce_after_shop_loop_item', 'risbl_hide_add_to_cart_category'); 
  } 
}

Hope the code snippets above help you hide the add to cart buttons in WooCommerce.

 68 total views,  1 views today

Leave a Comment

Your email address will not be published. Required fields are marked *