[英]WooCommerce custom out of stock text + specific product id
Here is what I am trying to do这是我想要做的
Problem: ALL products are at the moment being edited.问题:目前正在编辑所有产品。 I am not successfully applying it do specific product IDs.
我没有成功地应用它做特定的产品 ID。
This is what I tried so far这是我到目前为止尝试过的
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;
} }
Thanks!谢谢!
Try this code试试这个代码
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.