Luke Baumann
Luke Baumann

Reputation: 67

Make product purchasable when price is zero 0

I have some products that have a price of 0. By default woocommerce makes these product non-purchasable. I need customers to be able to select their quantity and add to cart for all products site wide.

I found this code snippet and thought it should work but it's not . What am i missing here?

add_filter( 'woocommerce_is_purchasable', 'wpa_109409_is_purchasable', 10, 2 );

function wpa_109409_is_purchasable( $purchasable, $product ){
    if( $product->get_price() == 0 )
        $purchasable = false;
    return $purchasable;
}

Upvotes: 0

Views: 5333

Answers (1)

Richard Abear
Richard Abear

Reputation: 186

Without having been able to look at the entire sourcecode im not certain if this will work

but you could try this:

add_filter( 'woocommerce_is_purchasable', 'wpa_109409_is_purchasable', 10, 2 );

function wpa_109409_is_purchasable( $purchasable, $product ){
    if( $product->get_price() >= 0 )
        $purchasable = true;
    return $purchasable;
}

Upvotes: 3

Related Questions