Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created June 24, 2025 11:54
Show Gist options
  • Save xlplugins/e6ddae8c93414a74003d7642fb25b579 to your computer and use it in GitHub Desktop.
Save xlplugins/e6ddae8c93414a74003d7642fb25b579 to your computer and use it in GitHub Desktop.
Shipping Method validtions
add_action( 'woocommerce_checkout_process', 'force_choose_shipping_method' );
function force_choose_shipping_method() {
if ( WC()->cart->needs_shipping() ) {
$chosen_method = WC()->session->get( 'chosen_shipping_methods' );
if ( empty( $chosen_method ) || empty( $chosen_method[0] ) ) {
wc_add_notice( __( 'Please select a shipping method to proceed.', 'woocommerce' ), 'error' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment