I am building a custom "Buy Now" plugin on woocommerce, when user clicks "Buy Now" button before going to checkout I want check if user selected variables. If he/she did not, alerts user choose options as add to cart or original buy now button does
You need to use javascript to achieve this
let's assume you give the button id as wc_buynow
$(document).on('click','#wc_buynow',function(){
let is_valid = 1;
$('select.wc-default-select').each(function(i){
if($(this).val() == ''){
let id = $(this).attr('id');
let attr_name = $("label[for='"+id+"']").text();
alert(attr_name+" is required!");
is_valid = 0;
}
});
if(is_valid){
// send ajax call to add product in cart and on success redirect to checkout
}
})