当前位置: 动力学知识库 > 问答 > 编程问答 >

php - WooCommerce custom stock status

问题描述:

I am trying to overwrite the woocommerce_product_is_in_stock filter/hook, I have already found this answer:

Additional stock options in woocommerce

add_filter('woocommerce_product_is_in_stock', 'woocommerce_product_is_in_stock' );

function woocommerce_product_is_in_stock( $is_in_stock ) {

global $product;

// array of custom stock statuses that will have add to cart button

$stock_statuses = array('onrequest','preorder');

if (!$is_in_stock && in_array($product->stock_status, $stock_statuses )) {

$is_in_stock = true;

}

return $is_in_stock;

}

But that only helps me partway, this does return the product as in stock for most instances but whenever I try to view the cart the product cannot be found. The global $product seems to be "NULL" whenever I var_dump it.

How can I change this code so that the cart will allow me to order the product with my own custom stock status?

Thanks in advance!

分享给朋友:
您可能感兴趣的文章:
随机阅读: