Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”

Question

I created a plugin to add a new stock status to my woocommerce products. I used this as my reference (copy and pasted into my plugins php file): Create WooCommerce custom stock option that is non-purchasable.

Everything works as it should but I also want to disable the add to cart button for products with

is_stock_status( 'callavailability' )

I think i can acheive this with

add_filter( 'woocommerce_is_purchasable', false );

but I can’t figure out how to trigger the filter for only those specific products.

Here is the code I have so far:

add_filter( 'woocommerce_is_purchasable', 'command' );

function command( $value )
{
    if ( $product->is_stock_status( 'callavailability' ) )
        $value[] = 'false';

    return $value;
}

When I put this in my child theme’s functions.php via ftp, all pages that contain products (single, archive, etc) are blank with only the site header visible and no footer. All non-woocommerce pages work fine and even products displayed via shortcode show up on the non-woocommerce pages.

I have no idea what I’m doing wrong and I have literally tried over 50 examples and guides on google and I always either get blank pages or http 500 errors.

Once I get this figured out, I also need to add a badge (Something like the sale badge) with custom text and styling (colour) I assume its not too difficult since when products are set to Out of stock they have an ” out of stock” badge already.

Thanks

0
, , Tristan Glaw 10 months 0 Answers 146 views 0

Leave an answer