Force choosing a shipping method in WooCommerce cart

Sometimes is necessary to have a shipping method selected in cart page, before proceeding to checkout.

This can be achieved using a short jQuery function inserted in head via a php function added in functions.php:

// force shipping method in cart
function mo_prevent_proceed_to_checkout() {
 echo ' <script>
  jQuery(".woocommerce-cart .wc-proceed-to-checkout a.checkout-button").on("click",function(e){
   var _this = this;
   alert("Please choose your shipping method!");
   jQuery(".shipping-calculator-form .button").on("click",function(){

This works by preventing a “default” option, which can be actually a shipping method previously chosen by visitor and remembered via cookie – in which case this is not exactly useful.

However, it can be improved by adding a conditional checking for the current shipping method and outputting the jQuery code only when necessary 🙂

Leave a Reply