Geolocated Pricing for Your WordPress Site – A Freemius integration tutorial
I released Contextual Related Posts Pro in June and followed up with Top 10 Pro in September. Both plugins use FreemiusOpens in a new window to handle licensing. Amongst other things, the benefit of going with Freemius is that I can easily offer licences in USD, GBP or EUR.
In this tutorial, you’ll learn how to set up multi-currency plans in Freemius and then configure your website’s pricing page to display pricing in the best currency as applicable automatically.
Step 1: Set up the Plans in Freemius
Once you have set up your product in Freemius, navigate to the Plans page and either Add a new plan or click on an existing one to modify it.
In the plan’s config, you’ll find a new dropdown labelled Add Currency. Click it and select the desired currency. I’ve added GBP and EUR currencies for my plugins’ plans in addition to USD.
Make a note of the currency exchange you’re using to set the prices in GBP and EUR as we’ll need to use it for our script in the next step.
Once you’ve set up the price of the license in each currency, buyers will be able to choose between these currencies on the Checkout screen. Here’s what the checkout screen for Contextual Related Posts Pro looks like with the drop-down. Since I’m in the UK, my site automatically shows currencies in GBP!

Step 2: Create the Pricing Table HTML
First, let’s create the HTML structure for our pricing table. You can add this to your plugin’s page template or use a shortcode to display it. I created mine using the block editor but set the necessary classes that I could target with JavaScript.
In my case, I have a Pro plan that allows a user to buy single-site or multisite licenses. To make the JavaScript dynamic, I have the classes set as pro-plan-1, pro-plan-5, etc.
Step 3: Enqueue JavaScript and Localize Script Data
Within your theme’s functions.php or any other functional plugin, add the following PHP code that will enqueue the js file we’ll build in the next step.
Update the script data to that of your plugins as well as the exchange rate that you want to use. The usdPrices array contains the various plans and their prices in USD.
This code enqueues jQuery, the Freemius checkout script, and your custom pricing script. It also passes important data to your JavaScript using wp_localize_script().
Step 4: Create the JavaScript file
Create a new file called pricing.js in your plugin’s js directory and add the following code:
Explaining the Script
Here’s a breakdown of what the script does:
- Freemius Configuration: It sets up the Freemius checkout handler with your WebberZone plugin’s details.
- Event Handlers: It attaches click event handlers to the “Buy Now” buttons for different plans.
- Geo-based Pricing:
- Fetches geographical data from Freemius API to determine the user’s location and currency.
- Calculates prices based on predefined USD to GBP and EUR conversion rates.
- Updates the pricing table with the converted prices and appropriate currency symbols.
- Caching: Implements a simple caching mechanism using
localStorageto store geographical data and reduce API calls directly within the user’s browser. - DOM Updates: Updates the pricing displayed on the webpage based on the calculated prices and currency.
Customisation and Best Practices
- Exchange Rates: Remember to update the exchange rates in your PHP code if you’re changing your Freemius plans to ensure there is consistency in the pricing.
- Responsive Design: Ensure your pricing table is responsive for different screen sizes.
- Testing: Thoroughly test the checkout process with Freemius sandbox mode before going live.
- Optimization: Consider selectively loading the pricing script if it’s not needed on every page. I only load this on selected page IDs on this site.
- WordPress Coding Standards:
- Use a prefix for functions to avoid naming conflicts with other plugins. I have
wz_in the script above. - Follow WordPress naming conventions for functions and variables.
- Add appropriate inline documentation for functions.
- Use a prefix for functions to avoid naming conflicts with other plugins. I have
Conclusion
Implementing dynamic pricing with Freemius in your WordPress plugin offers a powerful way to customise your pricing based on user location and currency. This approach not only enhances the user experience by displaying prices in local currencies but also streamlines the checkout process.
By following this tutorial, you’ve learned how to set up the pricing table, handle currency conversions, and integrate Freemius checkout seamlessly. You’re well-equipped to offer a more personalised and efficient purchasing experience for your plugin users, potentially boosting conversions and customer satisfaction.
Using this script on your site, comment below and let me know your experience!

