Using Gravity Forms ‘gform_currency_setting_message’ PHP action

The gform_currency_setting_message is a Gravity Forms PHP action hook that adds a customized message after the currency drop-down menu within the Settings page of your Gravity Forms dashboard.

Usage

You can use the gform_currency_setting_message hook to display a custom message related to the chosen currency. Here’s a basic usage example:

add_action('gform_currency_setting_message', 'currency_message');
function currency_message() {
    // your custom code here
    return 'Your message goes here';
}

Parameters

  • $message (string): The default message. This is an empty string which will be replaced by your custom message.

More information

See Gravity Forms Docs: gform_currency_setting_message

This action hook was originally located in GFSettings::gravityforms_settings_page() in settings.php. In Gravity Forms 2.5 it was moved to GFSetting::currency_message_callback().

Examples

Display a Message for a Specific Currency

If you want to show a message when a particular currency is selected, you can do it as follows:

add_action('gform_currency_setting_message', 'currency_message');
function currency_message() {
    // Get the current selected currency
    $currency = RGCurrency::get_currency();

    if ($currency == 'USD') {
        esc_html_e('US Dollars is the only supported currency by this payment gateway.', 'your_text_domain_here');
    }
}

This code checks the currently selected currency. If it’s US Dollars, it displays a custom message.

General Warning Message

If you want to show a general warning message regardless of the selected currency, you can use this code:

add_action('gform_currency_setting_message', 'currency_message');
function currency_message() {
    esc_html_e('Please note that currency conversion rates may apply.', 'your_text_domain_here');
}

This code displays a warning message about potential currency conversion rates.

Different Messages for Different Currencies

If you want to display different messages for different currencies, you can do so using a switch statement:

add_action('gform_currency_setting_message', 'currency_message');
function currency_message() {
    // Get the current selected currency
    $currency = RGCurrency::get_currency();

    switch ($currency) {
        case 'USD':
            esc_html_e('US Dollars is the only supported currency by this payment gateway.', 'your_text_domain_here');
            break;
        case 'EUR':
            esc_html_e('Euro is currently unavailable.', 'your_text_domain_here');
            break;
        default:
            esc_html_e('Your selected currency is not supported.', 'your_text_domain_here');
            break;
    }
}

In this example, different messages are displayed based on the selected currency.

Display Currency Conversion Rates

You can use an API to fetch and display currency conversion rates. Here is a simplified example:

add_action('gform_currency_setting_message', 'currency_message');
function currency_message() {
    // Get the current selected currency
    $currency = RGCurrency::get_currency();

    // API call to get conversion rate (please replace with real API call)
    $conversion_rate = api_call_to_get_conversion_rate($currency);

    esc_html_e("The current conversion rate is: $conversion_rate", 'your_text_domain_here');
}

This example fetches the conversion rate for the selected currency and displays it. Remember to replace the placeholder API function with a real one.