显示“缺货"产品在 Woocommerce 中缺货时的标签 [英] Show "out of stock" label when product is on backorders in Woocommerce
问题描述
在 Woocommerce 中,关于产品库存可用性显示文本,我正在寻找一种方法来显示缺货"文本,即使激活了允许延期交货,无需通知.
In Woocommerce, regarding products stock availability displayed text, I'm looking for a way to show the "Out of stock" text even when allow backorder is activated, without require notification.
当 Woocommerce 中的产品缺货时,如何显示缺货"标签?我正在使用店面主题
How can I show "out of stock" label when product is on backorders in Woocommerce? I'm using storefront theme
推荐答案
Woocommerce 允许您在通知或不通知的情况下启用延期交货.启用延期交货通知后,将显示文本可延期交货",并且没有通知就不会显示任何内容.
Woocommerce allows you to enable backorders with or without notification. When backorder notification is enabled the text "Available on backorder" is displayed and nothing for without notification.
当产品处于缺货状态时,以下将显示文本缺货(可以缺货)",当启用缺货时没有通知:
When products are on backorder, the following will display the text "Out of stock (can be backordered)", when backorder is enabled without notifications:
add_filter( 'woocommerce_get_availability_text', 'custom_backorders_stock_availability_text', 10, 2 );
function custom_backorders_stock_availability_text( $availability, $product ) {
if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
if ( ! $product->backorders_require_notification() ) {
$availability = __( 'Out of stock (can be backordered)', 'woocommerce' );
}
}
return $availability;
}
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
产品设置(在库存标签上):
库存可用性显示文本(缺货时):
或者对于所有产品缺货的情况(即使有通知),请改用:
Or for all cases when product is on backorders (even with notification), use instead:
add_filter( 'woocommerce_get_availability_text', 'custom_backorders_stock_availability_text', 10, 2 );
function custom_backorders_stock_availability_text( $availability, $product ) {
if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
$availability = __( 'Out of stock (can be backordered)', 'woocommerce' );
}
return $availability;
}
这篇关于显示“缺货"产品在 Woocommerce 中缺货时的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!