Show Payment Notices by Visitor IP in WooCommerce

Autor:Lisa Farrell · 2026-06-01

WooCommerce stores can show different payment notices on checkout, product pages, or pricing pages according to visitor region. PHP inserts the notice container, and the browser calls the IP interface to replace the message.

API explanation

A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.

{"ip":"185.220.236.7","country":"TW","region":"Taiwan","city":"Taipei"}

Use cases

These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.

  • These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.
  • Show Payment Notices by Visitor IP in WooCommerce
  • API explanation
  • SEO and UX recommendations

Implementation logic

Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.

  • Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
  • A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.
  • All examples below use https://my.ipin.io/info directly, with localized comments and interface text.
  • Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.

Code example

All examples below use https://my.ipin.io/info directly, with localized comments and interface text.

functions.php / plugin

function ipin_geo_payment_notice_html() {
    $box_id = 'ipin-payment-notice-' . wp_generate_uuid4();
    ob_start();
    ?>
    <div id="<?php echo esc_attr($box_id); ?>" class="woocommerce-info ipin-payment-notice">Welcome. This is the default content.</div>
    <script>
    (async function () {
      const el = document.getElementById("<?php echo esc_js($box_id); ?>");
      const defaultText = "Welcome. This is the default content.";
const contentMap = { TW: "Content for Taiwan visitors", US: "Content for United States visitors", JP: "Content for Japan visitors" };
try {
  // Browser-side call to /info: detects the visitor IP.
  const info = await fetch("https://my.ipin.io/info").then(res => res.json());
  el.textContent = contentMap[info.country] || defaultText;
} catch (e) {
  // Keep the default value when the API request fails.
  el.textContent = defaultText;
}
    })();
    </script>
    <?php
    return ob_get_clean();
}
add_action('woocommerce_review_order_before_payment', 'ipin_geo_payment_notice');
function ipin_geo_payment_notice() { echo ipin_geo_payment_notice_html(); }
add_shortcode('geo_payment_notice', 'ipin_geo_payment_notice_shortcode');
function ipin_geo_payment_notice_shortcode() { return ipin_geo_payment_notice_html(); }

Shortcode

[geo_payment_notice]

SEO and UX recommendations

Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.

Common mistakes

The following issues affect article accuracy, code usability, and the credibility of the API explanation.

  • The following issues affect article accuracy, code usability, and the credibility of the API explanation.
  • Default content should remain complete and readable, while regional content acts as an enhancement. Search engines can crawl stable content, and the page remains usable if the API fails.
  • Before implementation, identify the requester: server requests return server IP, while browser requests return visitor IP.
  • These scenarios show the value of the IP information interface while clearly separating server IP from visitor IP.

Summary

A browser-side call checks the visitor IP and returns the visitor IP, country, region, and city. It is suitable for localized content display.

FAQ

The questions below are written specifically for this article and are directly related to the implementation.

Question:What is the difference between the hook and the shortcode?
Answer:The hook displays the notice automatically on checkout, while the shortcode inserts it on product pages, pricing pages, or posts.
Question:Does this code change payment gateways?
Answer:No. It only shows explanatory text and does not enable, disable, or reorder payment gateways.
Question:Why call the API in the browser?
Answer:The notice should reflect the visitor IP, and a browser request represents the visitor.
Question:Can the notice include links?
Answer:Yes, but configurable HTML should be sanitized with an allowlist.
Question:Can checkout caching cause issues?
Answer:Yes. WooCommerce checkout pages generally should not be full-page cached.