Home / Archive / Add Empty Option To Countries List
Duplicate Snippet

Embed Snippet on Your Site

Add Empty Option To Countries List

Add an empty "Select your country"option at the start of the list of countries in the donation form.

Code Preview
php
<?php
/**
 * In this example we add an empty "Select your country"
 * option at the start of the list of countries in the
 * donation form.
 */
add_action(
	'init',
	function() {
		$fields    = charitable()->donation_fields();
		$field     = $fields->get_field( 'country' );
		$form      = $field->donation_form;
		$countries = array_merge(
			array( '' => 'Select your country' ),
			$form['options']
		);
		$field->set( 'donation_form', 'options', $countries );
		$field->set( 'donation_form', 'default', '' );
	}
);

Comments

Add a Comment