Website Building » WooCommerce » How Do I Hide a Button in WooCommerce?

How Do I Hide a Button in WooCommerce?

Last updated on January 23, 2023 @ 1:04 pm

 

If you’re running a WooCommerce store, there are going to be times when you need to hide a button. Maybe it’s a “Add to Cart” button on a product that’s out of stock, or a “Buy Now” button on a product that’s not yet released.

Whatever the reason, hiding buttons in WooCommerce is actually pretty easy to do.

There are two ways to hide buttons in WooCommerce: with CSS and with PHP. We’ll cover both methods so you can choose the one that’s right for you.

Hiding Buttons with CSS

The first method is to use CSS to hide the button. This is the simplest method, and it doesn’t require any coding knowledge. All you need to do is add a bit of CSS code to your theme’s stylesheet.

To do this, log into your WordPress site and go to Appearance > Editor. On the right hand side, you’ll see a list of files in your theme. Find the file called style.css and click on it to edit it.

Once you’re in the editor, scroll down until you find the section of code that controls the styling of the “Add to Cart” button. It will look something like this:

PRO TIP: If you are considering hiding a button in WooCommerce, be aware that this may impact your ability to use certain features or perform certain actions on your store. Additionally, hidden buttons may be difficult for customers to find, which could impact their ability to purchase items from your store.
.add-to-cart-wrap .button { .. }

All you need to do is add the following line of code within that section:

.button { display: none; }

What this does is tell the browser not to display the button. You can save your changes and check your site to see that the button has been hidden.

Hiding Buttons with PHP

If you want more control over which buttons are hidden and when, then you can use PHP.
To do this, log into your WordPress site and go to Appearance > Editor. Find the file called functions.php and click on it to edit it.

<?php
function my_HideButtons() { ?>

<style>
  .button { display: none !important;}
  .variations_form .single_variation_wrap .button { display: none !important;}
  #place_order { display: none !important;}
</style>

<script>
  jQuery(document).ready(function($) {
    $("input#submit").click(function() {
      $("#place_order").trigger("click");
    });
  });
</script>

<?php }
add_action('wp_head','my_HideButtons'); ?>

Hiding buttons in WooCommerce gives you more control over your store and allows you to customize the user experience. You can hide buttons with CSS or with PHP, depending on which method best suits your needs.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.