在 WooCommerce 中,由于某种原因,我收到此错误:
警告:在第 32 行的 /home//wp-content/themes/flat/functions.php 中为 foreach() 提供的参数无效
该错误仅出现在简单的产品中,而不是具有多种变体的可变产品。这个错误似乎在这一行:
foreach($available as $i) {
任何帮助都会很棒!
这是我的代码:
/**
* Backorder Hook
**/
function backorder_text($available) {
foreach($available as $i) {
$available = str_replace('Available on backorder', 'This size is on backorder : Dont Miss out!<BR><span style="font-weight: normal;">Buy it now and we will dispatch as soon as they arrive</span>', $available);
}
return $available;
}
add_filter('woocommerce_get_availability', 'backorder_text');
add_filter( 'woocommerce_get_availability' , 'revised_woocommerce_get_availability' , 10, 2 );
function revised_woocommerce_get_availability( $available_array , $product) {
if ( $product->managing_stock() ) {
if ( !($product->is_in_stock() && $product->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount' )) && ($product->backorders_allowed() && $product->backorders_require_notification()) ) {
$custom_meta_value = get_post_meta( $product->id, 'Out_of_stock_message', true );
$available_array["availability"] = $custom_meta_value;
}
}
return $available_array;
}