admin管理员组文章数量:1309995
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
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
Share Improve this question edited Sep 26, 2019 at 16:40 Tristan Glaw asked Sep 26, 2019 at 16:34 Tristan GlawTristan Glaw 111 silver badge4 bronze badges1 Answer
Reset to default 2You are using not existing variable $product
try this:
add_filter( 'woocommerce_is_purchasable', 'command', 10, 2 );
function command( $value, $product ) {
if ( $product->is_stock_status( 'callavailability' ) )
$value[] = 'false';
return $value;
}
The first parameter is actually a boolean value.
本文标签: functionsSet quotwoocommerceispurchasablequot to false for specific quotproductgtisstockstatusquot
版权声明:本文标题:functions - Set "woocommerce_is_purchasable" to false for specific "$product->is_stock_status& 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741859408a2401534.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论