
Developers FAQ
- Can I use If-So with the Advanced Custom Fields (ACF) WordPress plugin?
Yes. You can use If-So with the ACF plugin.
The first step is to create an If-So trigger and paste its shortcode inside the custom field. Since Advanced Custom Fields do not render shortcodes by default, next you’ll need to add the following filters to your functions.php file. Please feel free to contact us if you need help with that.If you’d like to use If-So inside a Text field:
add_filter(‘acf/format_value/type=text‘, ‘do_shortcode’);If you’d like to use If-So inside a Text Area field:
add_filter(‘acf/format_value/type=textarea’, ‘do_shortcode’); - How can I access the geolocation data detected by If-So in PHP?
If-So detects the visitor’s location using an IP-to-location database, and you can access this data for your own logic or integrations.
Use the following code to retrieve the detected location:
require_once(IFSO_PLUGIN_BASE_DIR. 'services/geolocation-service/geolocation-service.class.php'); $geo_data = \IfSo\Services\GeolocationService\GeolocationService::get_instance()->get_user_location();Want to capture the user’s location using JavaScript? Learn how
- How can I access the visitor’s country in JavaScript?
You can make the visitor’s location available in JavaScript by retrieving the geolocation data in PHP and passing it to a JavaScript variable.
Add the following code to your theme’s functions.php file:
add_action('wp_enqueue_scripts', function(){ if(!defined('IFSO_PLUGIN_BASE_DIR')) return; require_once(IFSO_PLUGIN_BASE_DIR. 'services/geolocation-service/geolocation-service.class.php'); $geo_data = \IfSo\Services\GeolocationService\GeolocationService::get_instance()->get_user_location(); $ifso_country = !empty($geo_data->get('countryCode')) ? $geo_data->get('countryCode') : ''; if(function_exists('wp_add_inline_script')) wp_add_inline_script('if-so',"var ifso_country = '{$ifso_country}';",'after'); });This will expose the visitor’s country as a JavaScript variable named ifso_country, which you can use in your scripts.
You can adapt this approach to expose other geolocation values, such as city or state, by adjusting the data retrieved in the code.
- Can I embed a trigger directly in a page template?
Yes, you can. Learn more.
- How do I enable Ajax for a specific trigger that is embedded using PHP (for developers)?
If you want to enable Ajax loading for a specific trigger that is embedded directly in the page template using a PHP code, you can use the “echo do_shortcode(‘…’);” function
<?php echo do_shortcode('[ifso id="123" ajax="yes"]'); ?> - Are there any limitations when testing If-So in a local environment?
The only limitation to keep in mind is that the geolocation service will not function properly. This means that dynamic content with geolocation conditions will be treated as if the condition is not met.
If you wish to set location-based content and preview how it will appear to users when the condition is met, you can make use of the “testing mode” button. This feature enables you to force the display of the specified version, giving you a visual representation of the final result on your site.
Do license activations in a local environment count toward the total number of license activations?
Yes, but you have the flexibility to deactivate the license once the development is complete and activate it on another site of your choice.