This commit is contained in:
paoloar77
2024-05-18 20:05:57 +02:00
parent c00feb1ef9
commit e3b0517f93

View File

@@ -6064,6 +6064,26 @@ function showarray($array)
echo '<pre>' . json_encode($array, JSON_PRETTY_PRINT) . '</pre>';
};
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 "<span class='badge badge-success'>Preorder</span>" . $ispreorder . "<br>";
}
}