[英]Replace Woocommerce product stock status with a custom field value
Does anybody know some example filter to fill the stock status text with value from custom field? 有人知道一些示例过滤器用自定义字段中的值填充库存状态文本吗?
DB: D B:
Product 1, stock_status = in-stock, stock_status_custom = '5 days'
Product 2, stock_status = in-stock, stock_status_custom = '10 days'
CODE: 码:
function customGetStockTextForProduct($productId){
return get_field('stock_status_custom', $productId);
}
add_filter('customGetStockTextForProduct', 'customGetStockTextForProduct');
You could try to use woocommerce_get_availability
filter hook this way: 您可以尝试通过以下方式使用woocommerce_get_availability
过滤器挂钩:
add_filter( 'woocommerce_get_availability', 'custom_availability_text', 10, 2 );
function custom_availability_text( $availability, $product ) {
$custom_text = get_field( 'stock_status_custom', $product->get_id());
if( ! empty($custom_text) )
$availability['availability'] = $custom_text;
return $availability;
}
Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 It should work. 它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.