在WooCommerce,由於某種原因,我得到這個錯誤:PHP錯誤鉤
Warning: Invalid argument supplied for foreach() in /home//wp-content/themes/flat/functions.php on line 32
誤差只有簡單的產品,而不是變型產品具有多種變化出現。這個錯誤似乎是在這條線:
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;
}