Home / Archive / Change Accepted Countries Per Campaign
Duplicate Snippet

Embed Snippet on Your Site

Change Accepted Countries Per Campaign

This example shows how to change the accepted countries list on a per-campaign basis.

Code Preview
php
<?php
/**
 * This example shows how to change the accepted countries list on a per-campaign basis.
 *
 * @param  array $fields The fields in the form.
 * @return array
 */
function ed_set_list_of_accepted_countries_by_campaign( $fields, $form ) {
	/* If a country field doesn't exist, stop right here. */
	if ( ! array_key_exists( 'country', $fields ) ) {
		return $fields;
	}
	if ( 1017 === $form->get_campaign()->ID ) {
		$fields['country']['options'] = array(
			'AU' => 'Australia',
		);
	}
	return $fields;
}
add_filter( 'charitable_donation_form_user_fields', 'ed_set_list_of_accepted_countries_by_campaign', 10, 2 );

Comments

Add a Comment