为了账号安全,请及时绑定邮箱和手机立即绑定

WooCommerce 自定义缺货文本 + 特定产品 ID

WooCommerce 自定义缺货文本 + 特定产品 ID

PHP
弑天下 2023-11-03 16:47:07
这就是我想做的检测特定产品是否有库存如果是,请编辑自定义库存消息在 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;

}


查看完整回答
反对 回复 2023-11-03
  • 1 回答
  • 0 关注
  • 72 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信