如果未选中产品级的启用库存管理,则希望在“产品”页面中显示有关库存状态的消息。
当股票状态为
"Available"
“
这有可能吗?
发布于 2020-03-19 13:19:08
使用下面的代码,您可以检查股票状态并相应地调整消息。
function change_stock_message( $text, $product ) {
// Managing stock NOT checked
if ( !$product->managing_stock() ) {
// Get stock status
if ( method_exists( $product, 'get_stock_status' ) ) {
$stock_status = $product->get_stock_status();
}
// Check stock status, adjust the message accordingly
switch ( $stock_status ) {
case 'instock':
$text = __( 'Available', 'woocommerce' );
break;
case 'outofstock':
$text = __( 'Out of stock', 'woocommerce' );
break;
case 'onbackorder':
$text = __( 'Available after 4-7 days', 'woocommerce' );
break;
}
}
return $text;
}
add_filter( 'woocommerce_get_availability_text', 'change_stock_message', 10, 2 );
https://stackoverflow.com/questions/60749190
复制相似问题