这就是我想做的检测特定产品是否有库存如果是,请编辑自定义库存消息在 A2C 按钮上方显示自定义消息(库存数量通知所在的位置)问题:所有产品目前正在编辑中。我没有成功地将其应用于特定的产品 ID。这是我到目前为止所尝试的add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);function wcs_custom_get_availability( $availability, $_product ) { global $product; // custom if ( $_product->is_in_stock() && $product_id = '6498' ) { $availability['availability'] = sprintf( __('✔️ Available but low in stock | 30-day No Questions Asked Money-Back Guarantee Applies', 'woocommerce'), $product->get_stock_quantity()); } // Out of stock if ( ! $_product->is_in_stock() ) { $availability['availability'] = __('Sorry, All sold out!', 'woocommerce'); } return $availability;}谢谢!
1 回答
GCT1015
TA贡献1827条经验 获得超4个赞
试试这个代码
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 10, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// custom
if ( $_product->is_in_stock() && $_product->get_id() == '6498' ) {
$availability['availability'] = sprintf( __('✔️ Available but low in stock | 30-day No Questions Asked Money-Back Guarantee Applies', 'woocommerce'), $_product->get_stock_quantity());
}
// Out of stock
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = __('Sorry, All sold out!', 'woocommerce');
}
return $availability;
}
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消