0
votes

im using Woocommerce and searching for a way to hide the "Add to cart"-Button on
a single-Product page IF the product is for free - I'm making a big CSV-Import and some product-prices are set to zero - i just want to hide the "add to cart" button on these products, so these are not buyable.

already asked this on the support page, but no success

Greets

2
turn out i can remove the button with: function remove_loop_button(){ remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); } add_action('init','remove_loop_button'); but how can i tell woocommerce to d this only if the price is zero? - Yilmaz Diskaya
One another option is to make quanity zero for those prducts, and add to cart will be automatically hidden. - Balram Singh

2 Answers

0
votes

I just used a bit of simple css to hide the "Add to cart" and the stock count area as below:

.post-300 .cart {

display:none !important;

}

If you view the source of the product page and search for:

class="post- 

This should give you the page post number that you can use to replace 300 in my example.

Your css selector might be slightly different depending on your wordpress theme etc. But you should get the idea. Hope this helps.

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