本文介紹了如果“管理庫存"顯示自定義庫存消息在 WooCommerce 中未啟用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
如果未選中在產品級別啟用庫存管理,我想在產品頁面中顯示有關庫存狀態的消息
If Enable stock management at the product level is not checked I would like to show a message in product page for the stock status
當庫存狀態為
- 有貨 - 有貨"
- 缺貨 - 缺貨"
- onbackorder - 4-7 天后可用"
有可能嗎?
推薦答案
使用以下代碼,您可以查看庫存狀態并相應地調整消息.
With the following code you can check the stock status and adjust the message accordingly.
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 );
這篇關于如果“管理庫存"顯示自定義庫存消息在 WooCommerce 中未啟用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!