mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/61065801/prevent-access-to-checkout-without-shipping-method-in-woocommerce/
9 lines
447 B
Text
9 lines
447 B
Text
add_action( 'woocommerce_check_cart_items', 'required_chosen_shipping_methods' );
|
|
function required_chosen_shipping_methods() {
|
|
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
|
|
|
|
if( is_array( $chosen_shipping_methods ) && count( $chosen_shipping_methods ) > 0 ) {
|
|
// Display an error message
|
|
wc_add_notice( __("A shipping method is required in order to proceed to checkout."), 'error' );
|
|
}
|
|
}
|