Skip to content

Instantly share code, notes, and snippets.

@odessy
Created November 29, 2018 14:31
Show Gist options
  • Save odessy/28dbc975e31fed8deae79eda3af59f19 to your computer and use it in GitHub Desktop.
Save odessy/28dbc975e31fed8deae79eda3af59f19 to your computer and use it in GitHub Desktop.
verify first step for handsome checkout page
jQuery(document).ready(function($){
var btn = $('.hcc-t5-step-1 .btn-step2');
if( btn.length == 0 ) btn = $('.btn-step1');
btn.before('<style>.btn-step1-wrapper{display:none;} .hcc-t6-step-1 .btn-step1-wrapper{margin-top: 20px; margin-bottom: 27px; display:block;} .hcc-step-1 .btn-step1,.hcc-step-2 .btn-step1, .hcc-step-2 .btn-step1-wrapper, .hcc-t5-step-2 .btn-step1-wrapper, .hcc-t5-step-3 .btn-step1-wrapper,.hcc-t5-step-1 .btn-step2, .hcc-t6-step-1 .btn-step1{display:none !important;}</style>');
btn.after('<button class="btn btn-success btn-lg wizard-button btn-block btn-step1-wrapper">'+btn.html()+'</button>');
$('.btn-step1-wrapper').on("click", function(event){
var inputs = $('.validate-required:visible').find('input');
var ready = true;
var messages = [];
inputs.each(function(i, item){
var input = $(item);
if(input.length && input.val() == ''){
messages.push(input.attr('name'));
ready = false;
}
});
var inputs = $('.validate-required:visible').find('select');
inputs.each(function(i, item){
var input = $(item);
if(input.length && input.val() == ''){
messages.push(input.attr('name'));
ready = false;
}
});
if(ready) {
$('form .woocommerce-NoticeGroup-checkout').remove();
btn.trigger('click');
} else {
$('form .woocommerce-NoticeGroup-checkout').remove();
$('form.woocommerce-checkout').prepend('<div class="woocommerce-NoticeGroup-checkout"><ul class="woocommerce-error"><ul><div>');
var errors = $('.woocommerce-checkout .woocommerce-error');
for(var e = 0; e < messages.length; e++){
//var i = 0;
//var msg = messages[e].replace(/(.)/g, function($1) {
// if(i == 0) $1 = $1.toUpperCase(); i++;
// if($1 == '_') {i = 0; $1 = ' ';}
// return $1;
//});
var msg = $('label[for='+messages[e]+']').html();
if(msg.length){
msg = msg.replace(/<\/?[^>]+(>|$)/g, "").replace('*', '');
errors.append("<li><strong>Billing "+msg+"</strong> is a required field.</li>");
}
}
if(messages.length) $('input[name="'+messages[0]+'"]').focus();
event.stopPropagation();
}
});
if( $('.hcc-embed-form-wrapper .steps').length > 0){
$('body').addClass('hcc-step-1');
$('.btn-step1').on('click', function(){
$('body').addClass('hcc-step-2').removeClass('hcc-step-1');
});
$('.steps .step1, .link-back1').on('click', function() {
$('body').addClass('hcc-step-1').removeClass('hcc-step-2');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment