Last active
August 29, 2015 14:03
-
-
Save JustinSainton/9dcb6367c46058c84f9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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