Website Building » WooCommerce » How Do I Hide the Cart Button in WooCommerce?

How Do I Hide the Cart Button in WooCommerce?

Last updated on January 17, 2023 @ 11:28 am

If you’re running a WooCommerce store, you might want to hide the cart button for certain products. For example, if you’re selling digital products, there’s no need to display the cart button.

To hide the cart button in WooCommerce, you need to add a little code to your functions.php file. Don’t worry, it’s not complicated!

PRO TIP: If you are considering hiding the cart button in WooCommerce, be aware that this may have unintended consequences. For example, if a customer has items in their cart and they visit a page where the cart button is hidden, they will not be able to access their cart or checkout. This could result in lost sales and frustrated customers.

Just add this code:

function my_custom_wc_button_function() {
  global $product;
   if( $product->is_type( 'simple' ) && $product->get_price() == 0 ) {
    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 );
   }
}
add_action( 'wp', 'my_custom_wc_button_function' );

This code will check if the product is simple and if it’s price is zero. If both conditions are met, it will remove the cart button. You can adjust the code to fit your needs.

And that’s it! You’ve successfully hidden the cart button in WooCommerce.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.