function wc_currency_get_prices() { $api_all = trim( (string) get_option('wc_currency_api_all', '') ); $symbols = explode(',', get_option('wc_currency_symbols', 'USD,AED')); $prices = []; $resp = wp_remote_get( $api_all, array( 'timeout' => 15 ) ); if ( is_wp_error($resp) ) { error_log('API ERROR: ' . $resp->get_error_message()); return []; } $body = wp_remote_retrieve_body($resp); error_log('RAW BODY: ' . $body); $data = json_decode($body, true); error_log('DECODED DATA: ' . print_r($data, true)); if ( isset($data['symbol']) ) { // حالت آبجکت تکی $sym = strtoupper($data['symbol']); $prices[strtolower($sym)] = $data['price'] . ' ' . $data['unit']; } elseif ( is_array($data) ) { // حالت آرایه foreach ($symbols as $sym) { $sym = strtoupper(trim($sym)); $found = 'N/A'; foreach ($data as $item) { if ( isset($item['symbol']) && strtoupper($item['symbol']) === $sym ) { $found = $item['price'] . ' ' . $item['unit']; break; } } $prices[strtolower($sym)] = $found; } } error_log('FINAL PRICES: ' . print_r($prices, true)); return $prices; }

