Skip to content

Instantly share code, notes, and snippets.

@kish2011
Created December 5, 2025 15:58
Show Gist options
  • Select an option

  • Save kish2011/0c35b318aa56bee80e3dc707ddba2972 to your computer and use it in GitHub Desktop.

Select an option

Save kish2011/0c35b318aa56bee80e3dc707ddba2972 to your computer and use it in GitHub Desktop.
Clear Billing Country on Checkout Load
<?php
add_filter( 'woocommerce_checkout_get_value', function( $value, $input ) {
// Run only on the front-end checkout page
if ( is_admin() || ! is_checkout() || is_wc_endpoint_url() ) {
return $value;
}
// Clear only the billing country on first load
if ( $input === 'billing_country' ) {
// If user has not submitted anything yet, force it blank
if ( empty( $_POST['billing_country'] ) ) {
return '';
}
}
return $value;
}, 10, 2 );
// Automatically Sync Billing Country if “Same As Shipping” is Checked
add_action( 'woocommerce_checkout_update_order_review', function( $post_data ) {
parse_str( $post_data, $data );
// If "same as shipping" is checked
if ( isset( $data['billing_same_as_shipping'] ) ) {
if ( isset( $data['shipping_country'] ) ) {
$_POST['billing_country'] = $data['shipping_country'];
}
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment