function wc_currency_get_prices() { $api_all = trim( (string) get_option('wc_currency_api_all', '') ); $symbols = explode(',', get_option('wc_currency_symbols', 'USD,AED')); $minutes = max( 1, intval( get_option('wc_currency_cache_minutes', 30 ) ) ); $prices = []; $resp = wp_remote_get( $api_all, array( 'timeout' => 15 ) ); if ( ! is_wp_error( $resp ) ) { $body = wp_remote_retrieve_body($resp); $data = json_decode($body, true); // برای تست: خروجی رو لاگ کن error_log(print_r($data, true)); if ( 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 ) { if ( isset($item['price']) ) { $found = $item['price'] . ' ' . $item['unit']; } break; } } $prices[strtolower($sym)] = $found; } } } set_transient('wc_currency_prices_cache', $prices, $minutes * MINUTE_IN_SECONDS); return $prices; }

