|
/ Documentation /Developer Hooks & Events/ suredonation_phone_geo_enabled Filter Hook

suredonation_phone_geo_enabled Filter Hook

Overview

The suredonation_phone_geo_enabled filter controls whether SureDonation uses an IP geolocation service to automatically detect a visitor’s country for the Phone field.

This filter acts as a global switch. Returning false disables IP-based country detection for all SureDonation Phone fields.

This can be useful when you want to avoid third-party IP geolocation requests for privacy, GDPR, or other compliance requirements.

When to Use This Filter

Use this filter when you need to control automatic IP-based country detection.

For example, you can use it to:

  • Disable third-party IP geolocation.
  • Improve privacy.
  • Support GDPR or other privacy requirements.
  • Prevent external geolocation requests.
  • Ensure all Phone fields use the default country.

Filter Signature

apply_filters( 'suredonation_phone_geo_enabled', true );

Parameters

ParameterTypeDescription
$enabledboolDetermines whether automatic IP-based country detection is enabled.

Default Value

The default value is: true

This means IP-based country detection is enabled by default.

Return Value

Return a boolean value:

Return ValueResult
trueAllows IP-based country detection to run.
falseDisables IP-based country detection. The Phone field defaults to us.

Basic Usage

Use add_filter() to register your callback.

add_filter( 'suredonation_phone_geo_enabled',  'your_custom_function', 10, 1);

function your_custom_function( $enabled ) {

    return $enabled;

}

Example: Disable IP-Based Country Detection

The following example disables automatic country detection for all SureDonation Phone fields.

// Disable IP-based country detection entirely.

add_filter( 'suredonation_phone_geo_enabled',   '__return_false');

When disabled, SureDonation skips the IP geolocation lookup and uses us as the default country.

Example: Conditionally Disable Detection

You can also use custom logic to determine whether IP-based country detection should be enabled.

add_filter( 'suredonation_phone_geo_enabled', 'mysite_disable_phone_geo', 10, 1);

function mysite_disable_phone_geo( $enabled ) {

    if ( defined( 'MY_PRIVACY_MODE' ) && MY_PRIVACY_MODE ) {

        return false;

    }

    return $enabled;

}

How It Works

When a SureDonation Phone field needs to determine the visitor’s country:

  1. SureDonation checks the suredonation_phone_geo_enabled filter.
  2. If the filter returns false, the geolocation lookup is skipped.
  3. The Phone field uses us as the default country.
  4. If the filter returns true, SureDonation continues with IP-based country detection.
  5. The country detected by the geolocation service can then be used by the Phone field.

Additional Conditions

Returning true does not guarantee that a geolocation request will be made.

SureDonation also skips IP-based country detection in certain contexts, including:

  • Admin requests.
  • REST API requests.
  • Requests with an empty IP address.
  • Private IP addresses.
  • Reserved IP addresses.

Privacy Considerations

This filter can be useful when your site’s privacy requirements do not allow visitor IP addresses to be sent to a third-party geolocation service.

Disabling the filter prevents the IP-based country detection request for all Phone fields.

Note: Disabling automatic detection does not prevent donors from manually selecting their country in the Phone field.

Phone_Markup::get_geo_country()

The default value is true.

When the filter returns a falsy value, country detection is skipped, and the Phone field defaults to US.

Related Hooks

  • suredonation_phone_geo_api_hourly_cap: Controls the hourly limit for IP geolocation API requests.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top