Zylu Country-Based Body Class
Adds country-specific body classes using Cloudflare IP geolocation and displays the country.
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/zyluco/wp-country-detector/archive/refs/heads/main.zipZylu Country-Based Pricing Plugin
This lightweight WordPress plugin helps you display different content or pricing blocks based on the visitor’s country, using Cloudflare’s IP geolocation feature.
🌍 Features
- Automatically detects visitor country using Cloudflare headers
- Adds useful CSS classes to the
<body>:visitor-indiaorvisitor-internationalvisitor-country-xx(e.g.,visitor-country-us,visitor-country-sa)
- Displays the visitor’s country code in the footer (for debugging)
- Includes built-in CSS to show/hide specific pricing blocks
🛠️ Installation
- Ensure your WordPress site is behind Cloudflare with IP Geolocation enabled in Network Settings.
- Prepare the plugin file by downloading the file zylu-country-detector.php and ZIP it.
- In your WordPress admin:
- Go to Plugins → Add New → Upload Plugin
- Upload the ZIP file and activate the plugin
✅ How It Works
✅ Body Classes Added
The plugin adds the following classes to the <body> tag:
visitor-indiaif visitor is from India (IN)visitor-internationalif from outside Indiavisitor-country-xxwherexxis the 2-letter country code in lowercase
✅ CSS Visibility Rules
The plugin injects this CSS automatically:
/* Hide all pricing sections by default */
.pricing-india,
.pricing-international,
[class^='pricing-'] {
display: none;
}
/* Show relevant pricing blocks based on visitor location */
body.visitor-india .pricing-india {
display: block;
}
body.visitor-international .pricing-international {
display: block;
}
body.visitor-country-in .pricing-india,
body.visitor-country-us .pricing-usa,
body.visitor-country-sa .pricing-saudi {
display: block;
}
💡 Use Cases
- Show India pricing to Indian visitors
- Show USD or AED pricing to international visitors
- Target country-specific discounts and plans using Elementor, shortcodes, or custom blocks
📌 Requirements
- WordPress
- Cloudflare (with IP Geolocation enabled)
📃 License
MIT License – feel free to use, modify, and contribute.
🤝 Contributing
Pull requests are welcome. If you’d like to improve detection, add filters, or expand functionality, feel free to open an issue or submit a PR.