Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/maikunari/geo-content-shortcode-for-woocommerce/archive/refs/heads/main.zipWC requires at least: 7.0 WC tested up to: 11.0.1
Display or hide content by visitor country using WooCommerce geolocation, with fallback text and an admin debug shortcode.
Description
Geo Content Shortcode for WooCommerce shows or hides content based on the visitor's country, using WooCommerce's built-in geolocation.
Features
- Show content only to visitors from listed countries
- Hide content from visitors in listed countries
- Optional fallback text when the visitor does not match
- Uses WooCommerce geolocation (customer session, IP lookup, then default location)
- Caches the detected country per IP for 12 hours
- Rate-limits IP lookups to 10 per hour per address
- [debug_geo] shortcode for administrators (prints country, IP, and detection method)
Usage
Show content to specific countries:
[geo_content country="US,CA"] This content is only visible to visitors from the United States and Canada. [/geo_content]
Hide content from specific countries:
[geo_content exclude="CN,RU"] This content is hidden from visitors in China and Russia. [/geo_content]
If both country and exclude are set, country wins and exclude is ignored.
With fallback content:
[geo_content country="US" fallback="Sorry, this content is only available in the United States."] Special offer for US visitors! [/geo_content]
Debug (administrators only):
[debug_geo]
Non-administrators see nothing. The shortcode prints the detected country, IP address, and which detection method was used.
When the country cannot be determined
By default the inner content is hidden and the fallback attribute is shown (if you set one). There is no settings screen. To show the inner content instead, set the existing wgc_fallback_behavior option to show (for example via WP-CLI).
Requirements
- WordPress 6.0 or higher
- WooCommerce 7.0 or higher
- PHP 7.4 or higher
- For IP-based detection, set WooCommerce > Settings > General > Default customer location to Geolocate
Installation
- Upload the
geo-content-shortcode-for-woocommercefolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Ensure WooCommerce is installed and activated
- Go to WooCommerce > Settings > General and set "Default customer location" to "Geolocate"
- Use the [geo_content] shortcode in posts and pages
Frequently Asked Questions
Does this plugin require WooCommerce?
Yes. It uses WooCommerce's geolocation to detect the visitor's country.
How accurate is the geolocation?
Accuracy depends on WooCommerce's IP-based geolocation. VPNs and proxies can make the country wrong.
Can I use multiple country codes?
Yes. Separate two-letter ISO 3166-1 alpha-2 codes with commas, e.g. country="US,CA,GB".
What happens if I set both country and exclude?
The country list is used and exclude is ignored.
Does this work with caching plugins?
The plugin caches the country lookup per IP for 12 hours. Full-page caches can still serve the same HTML to every visitor. Exclude geo-targeted pages from page cache if that matters.
Can I test a different country?
Developers can use the wgc_override_country filter:
add_filter('wgc_override_country', function() { return 'GB'; });
Screenshots
- Content shown to a visitor in an included country, and the fallback text shown to everyone else.
- The admin-only [debug_geo] shortcode output, showing detected country, IP and detection method.
Changelog
1.0.0
- Initial release
- [geo_content] shortcode with country, exclude, and fallback attributes
- [debug_geo] shortcode for administrators
- Per-IP country cache and lookup rate limiting
Upgrade Notice
1.0.0
Initial release.
Privacy
This plugin uses the visitor IP address (via WooCommerce geolocation) only to detect country. The country result is cached in a transient for 12 hours. No personal data is stored permanently.