Skip to content

Instantly share code, notes, and snippets.

@JustinSainton
Last active August 29, 2015 14:03
Show Gist options
  • Save JustinSainton/9dcb6367c46058c84f9f to your computer and use it in GitHub Desktop.
Save JustinSainton/9dcb6367c46058c84f9f to your computer and use it in GitHub Desktop.
<?php
/**
* 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.
*
* @return string|null The meta value, or null, if unmodified.
*/
function zao_default_country( $value, $key ) {
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', 'zao_default_country', 15, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment