1
jQuery("#woocommerce_checkout_form").validate({


     highlight: function(element) {
            (jQuery(element).parent()).parent().addClass("woocommerce-invalid");
            (jQuery(element).parent()).parent().removeClass("woocommerce-validated");
        },
    unhighlight: function(element) {
            (jQuery(element).parent()).parent().removeClass("woocommerce-invalid");
            (jQuery(element).parent()).parent().addClass("woocommerce-validated");
        },


    submitHandler: function(form) {
        jQuery.ajax({
                type: "POST",
                data:values,
                url: jQuery(form).attr('action'),
                success: function(data){
                    //alert('ajax load');
                    //window.location.href = "http://demo7.web.dev1.bl/wp-content/plugins/woocommerce/templates/checkout/checkout.php";
                }
            });

            return true;

        //jQuery(form).ajaxSubmit();
    },
     rules: {

        billing_phone: {
            required: true,
            minlength:10,
            maxlength:10,
            number: true,
        },

        billing_postcode: {
            required: true,
            minlength:6,
            maxlength:6,
            number: true
        },

        shipping_postcode: {
            required: true,
            minlength:6,
            maxlength:6,
            number: true
        }
    },

    messages: {        
    billing_phone: {
        required: "Enter Phone Number", 
        minlength:"Please 10 Digit Phone Number",
        maxlength:"Please 10 Digit Phone Number",           
        number: "Please enter a valid quantity"
      },
      billing_postcode: {
        required: "Enter Valid Zipcode", 
        minlength:"Please enter six digits Zipcode",
        maxlength:"Please enter six digits Zipcode",           
        number: "Please enter a valid Zipcode"
      },

      shipping_postcode: {
        required: "Enter Valid Zipcode", 
        minlength:"Please enter six digits Zipcode",
        maxlength:"Please enter six digits Zipcode",           
        number: "Please enter a valid Zipcode"
      }

    }

});

This is the code that I am using to add extra validations on zipcode and phone but even in the case of not match it submit the form to payment. Is it possible to prevent form submission and stays on the checkout page after error just like default validations wokrs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.