Sorry! Internet Explorer is not supported on this site. Please view on Chrome, Firefox, or Edge.
Having fun at Zao is one of our values. We’ve put limited animated flourishes throughout our site to communicate our love of levity. We also recognize that onscreen movement is not fun or possible for everyone. We've turned off all our animations for you per your browser's request to limit motion. That said, we don't want you to miss out on the party.
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.
This file contains hidden or 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
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!
Join the Conversation
6 Comments
This is very nice. Now what do I do with this code snippet?
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.
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!