I use woocommerce. How to hide the "Add to cart" Button on a single-Product page IF the product is for free (0 $) . Have an idea to do it?


Please try to add following code into your theme functions.php file

function remove_add_to_cart_option( $purchasable, $product ){
    if( $product->get_price() == 0 )
        $purchasable = false;
    return $purchasable;
add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_option', 10, 2 );

Replace below function instead of above and check again

 * Override via functions.php
 if (!function_exists('woocommerce_template_loop_add_to_cart')) {
 function woocommerce_template_loop_add_to_cart() {
    global $product;
    if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) return;

Let me know if any query.

Hope it will help you !

  • This code will replace the add to cart with more information. i want remove this. – omid chahardoli Mar 28 at 13:57
  • @omidchahardol i have updated my answer so please check and let me know if any query :) – Pratik Patel Mar 29 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.