가이드가이드

WooCommerce 통화 변환

WooCommerce 통화 변환. 코드, 캐시, 최신성 메타데이터를 포함한 실용 가이드입니다.

2026년 9월 20일 · 7분 분량

자격 증명을 노출하지 않고 서버에서 구현하며 출처와 관측 시각을 보존합니다.

  • API 키는 서버에만 보관합니다.
  • 통화 코드와 금액을 검증합니다.
  • 성공한 응답을 캐시합니다.
  • 출처와 관측 시각을 표시합니다.

단계 1

코드 예제
function exr_convert_for_display($amount, $from, $to) {    $from = strtoupper(sanitize_text_field($from));    $to = strtoupper(sanitize_text_field($to));    $cache_key = 'exr_' . md5($from . '_' . $to);    $rate = get_transient($cache_key);    if ($rate === false) {        $url = sprintf('https://api.exchangerate.dev/v1/convert/%s/%s/1', $from, $to);        $response = wp_remote_get($url, array(            'timeout' => 5,            'headers' => array('Authorization' => 'Bearer ' . EXCHANGERATE_API_KEY),        ));        if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {            return null;        }        $body = json_decode(wp_remote_retrieve_body($response), true);        $rate = isset($body['rate']) ? (string) $body['rate'] : null;        if ($rate === null) return null;        set_transient($cache_key, $rate, MINUTE_IN_SECONDS);    }    return (float) $amount * (float) $rate;}

단계 2

서버에서 실행하고 입력값을 검증하며 응답 메타데이터를 보존하세요.

코드 예제
add_filter('woocommerce_get_price_html', function ($html, $product) {    $estimate = exr_convert_for_display((float) $product->get_price(), 'USD', 'EUR');    if ($estimate === null) return $html;    return $html . '<small class="fx-estimate">Estimated ' .        wp_kses_post(wc_price($estimate, array('currency' => 'EUR'))) . '</small>';}, 10, 2);

단계 3

  • API 키는 서버에만 보관합니다.
  • 통화 코드와 금액을 검증합니다.
  • 성공한 응답을 캐시합니다.
  • 출처와 관측 시각을 표시합니다.
가이드

이 환율은 참고용이며 결제 가격이 아닙니다.

자주 묻는 질문

WooCommerce 통화 변환

문서화된 JSON 계약으로 통화 변환과 참고용 환율을 앱에 추가할 수 있습니다.

계속 읽기

무료 API 키로 시작하세요

무료 플랜으로 월 5,000건 요청 가능. 신용카드는 필요하지 않습니다.

무료 키 받기