Change Default Country for Billing Fields

Some payment gateways require that billing info, including country, be filled out. When using one of these gateways, you may want to change the country that is selected by default. This small code snippet will let you do that.

The snippet should be added to a custom plugin or your theme's functions.php file:

function pw_set_edd_default_country( $countries ) {

	// remove the country we want to make default. This is referenced by country code
	unset( $countries['MY'] );

	$new_default = array();

	// the key, MY, is our country code and the value, Malaysia, is the name of the country
	$new_default['MY'] = 'Malaysia';

	// combine the new country with the others
	return array_merge( $new_default, $countries );
}
add_filter( 'edd_countries', 'pw_set_edd_default_country' );