diff --git a/routes/web.php b/routes/web.php index 38206a20..ad335c43 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6064,6 +6064,26 @@ function showarray($array) echo '
' . json_encode($array, JSON_PRETTY_PRINT) . '
'; }; +function isKeyPresent($array, $key) +{ + foreach ($array as $item) { + if (isset($item['key']) && $item['key'] === $key) { + return true; + } + } + return false; +} + +function getValueByKey($array, $key) +{ + foreach ($array as $item) { + if (isset($item['key']) && $item['key'] === $key) { + return $item['value']; + } + } + return null; // If key is not found +} + Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $postid) { try { // Aggiorna Preorder @@ -6098,8 +6118,11 @@ Route::get('/aggiornapreorder/{idarticolo}/{postid}', function ($idarticolo, $po $found_key_version = array_search('Versione', array_column($variation->attributes, 'name')); if ($variation->attributes[$found_key_version]->option == 'Nuovo') { - if (isset($variation['meta_data']['_wpro_variable_is_preorder'])) { - $ispreorder = $variation['meta_data']['_wpro_variable_is_preorder']; + $arrmetadata = $variation['meta_data']; + + $found = isKeyPresent($arrmetadata, '_wpro_variable_is_preorder'); + if ($found) { + $ispreorder = getValueByKey($arrmetadata, '_wpro_variable_is_preorder'); echo "Preorder" . $ispreorder . "
"; } }