How to Hide Price and Add to Cart Button Woocommerce

Hide Price and Add to Cart Button WoocommerceTo hide the price and add to cart button in WooCommerce and maintain good coding practices, we’ll follow a similar approach to our previous tutorial on hiding the add to cart button. It is always advisable to create a child theme when making customization to your WooCommerce store using code snippets. This ensures that your modifications remain intact during theme updates.

Code Snippet to Hide Price and Add to Cart Button:

Now, let’s dive into the code snippet that will effectively hide the price and add to cart button on your WooCommerce shop and product pages. To implement this, follow the steps below:

Step 1: Create a Child Theme (if not already created)

If you haven’t created a child theme yet, consider the following steps:
  • Access Your WordPress Admin Dashboard:Log in to your WordPress admin dashboard using your administrator credentials.
  • Navigate to Themes:Go to “Appearance” in the left-hand menu. Click on “Themes.”
  • Add New Theme:Click on the “Add New” button to add a new theme.
  • Choose a Parent Theme:Select a suitable parent theme, ideally the one you’re currently using.
  • Add Theme Details:Provide a name for your child theme, a description, and other details as needed. Click on the “Create a Child Theme” button.

Step 2: Locate and Edit functions.php File

  • Navigate to the Theme Editor:Go to “Appearance” in the left-hand menu. Click on “Theme Editor.”
  • Select the Child Theme:Ensure that you have selected your child theme from the right-hand side of the Theme Editor.
  • Locate and Edit functions.php:Look for functions.php in the list of theme files on the right.Click on it to open the file in the editor.

Step 3: Add the Code Snippet

  • Paste the Code:Scroll to the end of the functions.php file.Paste the following code snippet:
// Code to hide price and add to cart button in WooCommerce shop and product pages
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);

Why Use the Code Snippet

  • If you are new to editing the code on a WordPress site, you may break your site.
  • If you have many changes, code snippets tend to be cumbersome to update since some may require an update with every WooCommerce software update. (If the hooks or filters you are using change, the code snippet may no longer work.)
  • Code snippets may create vulnerability to your website security since they are from different sources (third-party developers).
  • Code snippets are freely available and with no upfront costs.
  • Code snippets can be quick to implement for experienced developers who can customize them further.

What is the Alternative Solution

While code snippets do great work and get the job done quickly, they have some drawbacks, and that's the reason plugins exist.

Plugins are ideally organized code snippets that are scalable, dependable, and professionally written to help you keep your site safe and customize it with ease.

To make your work easier, I have put together my 10+ years of experience into a highly useful WooCommerce product (Whideit) that is geared toward hiding all unwanted elements on your store without wasting time.

  • Using Hideit is easy, and you can simply click a button to immediately disable the Add to Cart button along with the price and several other features you may want to hide from users.
  • I specifically designed it to help with my day-to-day work on client projects. I found it very useful and decided to share it with the WooCommerce community.
  • If you are interested, you can find it here. As one of my blog readers, do not forget to subscribe to my mailing list using the form below so that you can CLAIM your 20% OFF introductory discount for WHIDEIT.
  • I also occasionally send important updates in WooCommerce to help you update or keep your site up and running effectively and safely. You can also reach out if you need any further customization or help with hiding any feature on your WooCommerce store.

Conclusion

Visit your WooCommerce shop and product pages to confirm that the price and add to cart button are now hidden.
By following these steps, you’ve successfully implemented the code snippet to hide the price and add to cart button, ensuring a seamless customization process while maintaining the integrity of your WooCommerce store.

Remember to make changes cautiously, and consider creating a backup before modifying any theme files. If you encounter any issues or need further clarification, feel free to ask!

If you enjoyed this article or found it useful, you will also like these other articles that are useful guides for customizing your WooCommerce store: