В WooCommerce по какой-то причине я получаю такую ошибку:
Предупреждение: неверный аргумент для foreach () в /home//wp-content/themes/flat/functions.php в строке 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;
}