Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 13, 2020 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/b02265fdf807e0d81f74fe9dccf7de0d to your computer and use it in GitHub Desktop.
Save xadapter/b02265fdf807e0d81f74fe9dccf7de0d to your computer and use it in GitHub Desktop.
Snippet to change the default country and state on the WooCommerce checkout page. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
// Change the default country and state on checkout page.
// This works for a new session.
add_filter( 'default_checkout_country', 'xa_set_default_checkout_country' );
add_filter( 'default_checkout_state', 'xa_set_default_checkout_state' );
function xa_set_default_checkout_country() {
// Returns empty country by default.
// return null;
// Returns US as default country.
return 'US';
}
function xa_set_default_checkout_state() {
// Returns empty state by default.
// return null;
// Returns California as default state.
return 'CA';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment