WP-Ecommerce – Set Default Country

If the majority of your customers are in the same country in makes sense to make their checkout experience easier by setting the default country appropriately.

Add this to your THEME/functions.php file and change the returned country code as required.

function zao_default_country( $value ) {

	remove_filter( 'wpsc_get_visitor_meta_shippingcountry', __FUNCTION__, 15 );

	$current_value = wpsc_get_customer_meta( 'shippingcountry' );

	add_filter( 'wpsc_get_visitor_meta_shippingcountry', __FUNCTION__, 15 );

	if ( $current_value !== '' ) {
		return $value;
	} else {
		return 'NZ';
	}

}

add_filter( 'wpsc_get_visitor_meta_shippingcountry', 'zao_default_country', 15, 2 );

Original script found here:

http://zao.is/2014/07/set-default-shipping-country-wp-ecommerce/

although I had to remove the $key attribute from the function to stop errors when the function is called.