【发布时间】:2019-08-08 17:46:52
【问题描述】:
我创建了名为“事件”的自定义产品类型。在产品页面上,我想显示自定义库存状态,所以我使用以下代码:
add_action( 'woocommerce_before_add_to_cart_form', 'yy', 15 );
function yy() {
global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
if( $product->is_type( 'event' ) ){
if ( $product->stock ) { // if manage stock is enabled
if ( number_format( $product->stock,0,'','' ) > 0 ) { // if stock is low
echo '<p class="stock in-stock">' . number_format($product->stock,0,'','') . ' in stock</p>';
} elseif ( number_format( $product->stock,0,'','' ) == 0 ) {
echo '<p class="stock out-of-stock">' . __('Out of stock', 'behold-basic') . '</p>';
}
}
};
}
}
但是当库存为 0 时没有任何显示,应该是“缺货”。问题可能出在哪里?
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce stock