There are a few really great scenarios to set a default shipping country for your WP eCommerce shop. In a past iteration, we actually defaulted to the base country and region of the shop itself. There was some decent, though flawed and short-sighted logic behind this. We eventually reverted that behavior in favor of requiring users to choose their own shipping location.
While this behavior is more intuitive, from time to time, we do get users asking for the ability to default to a specific country. While the previous behavior is sometimes requested, other scenarios might include defaulting to the country where you receive most of your orders from. This could vary wildly depending on season or product line. The code below is a helpful start to defaulting to any country you desire. Note: The filter being used should return a country’s ISO code.
You’ll notice we’re using the variable filter for the visitor meta API that is specific to the key being called. There is also the more generic wpsc_get_visitor_meta
filter, but with the variable filter, we don’t need to check for the key being called.
Boom!
This is very nice. Now what do I do with this code snippet?
You can put it in a plugin of your own or in your theme’s functions.php file.
Justin I am getting a warning Missing argument 2 for zao_default_country(). If I remove the $key it seems to work or am I missing something
Hi John,
Hmm, that’s odd, as three parameters should actually be passed (value, key, and visitor ID). Perhaps confirm that you’ve added the action with the “2” for the last parameter, as in the gist? Otherwise, you should be fine to go ahead and remove the $key variable, as it is unused.
Thanks for commenting!