0

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?

1 Answer 1

0

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;
    woocommerce_get_template('loop/add-to-cart.php');
  }
}

Let me know if any query.

Hope it will help you !

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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