Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
How to check if all options are selected on woocommerce variable product

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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use javascript to achieve this

  1. override the WooCommerce product template to add a custom buy now button
  2. add click event on that buy now button and check if any variation option is selected or not.
  3. IF not give alert to the user
  4. If yes send an ajax call to add that product to the cart
  5. on success redirect the user to the checkout page

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
    }

    
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda