Woocommerce – Hide “add to cart” on free products

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 Answers
2

Look at the beginning of the add to cart templates in WooCommerce. At the beginning there is a check to determine whether the product is purchasable. Inside the is_purchasable() method in the product class is a filter. By default the product is not purchasable if there is no price set at all, but that can be extended to cover products for which the price is set to 0.

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

Leave a Comment