Home / Admin / Filter Countries JUST for Donation Forms
Duplicate Snippet

Embed Snippet on Your Site

Filter Countries JUST for Donation Forms

Changing the master country list in Charitable is not recommended unless you know what you are doing. The below script allows you to change the countries listed on any and all front-end donation forms. In theory you could be able to detect a campaign ID in this function and adjust countries on a per-campaign basis, but this is out of the scope of this snippet.

David Bisset PRO
<10
Code Preview
php
<?php
add_filter( 'charitable_default_donation_fields', 'charitable_filter_countries_donation_form', 10, 1 );
function charitable_filter_countries_donation_form( $donation_fields = array() ) {
	if ( empty( $donation_fields['country']['donation_form']['options'] ) ) {
		return $donation_fields;
	}
	$countries_for_donation_form = $donation_fields['country']['donation_form']['options'];
	// you can remove a country.
	unset( $countries_for_donation_form['CA'] ); 
	// ..or you can create your own set of countries and replace the defaults.
	// note that you need to use the correct two-letter abbreviations for the countries.
	// https://www.iban.com/country-codes
	$new_countries = array (
		'AZ' => 'Azerbaijan',
        'BS' => 'Bahamas'
	);
    $donation_fields['country']['donation_form']['options'] = $new_countries;
	
    return $donation_fields;
}

Comments

Add a Comment