Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Improves the WP eCommerce checkout for stores.
/**
* Defaults customer meta for shipping country to the good ol' US of A.
*
* A function like this could be really useful in defaulting to the country that is most commonly purchased from.
* Or even to the base country of the store. Sky's the limit, folks.
*
* @param null $value A null flag.
* @param string $key The meta key being passed to the customer meta API.
* @param int $id The current user/customer/visitor ID.
*
* @return string|null The meta value, or null, if unmodified.
*/
function elite_default_country( $value, $key = '', $id = '' ) {
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 'US';
}
}
add_filter( 'wpsc_get_visitor_meta_shippingcountry', 'elite_default_country', 15, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment