Home > Software design >  is it possible to disable/enable a button if a specific alert message is shown
is it possible to disable/enable a button if a specific alert message is shown

Time:06-13

so i'm having an issue with a plugin that i purchased for my wordpress ecommerce site b2b and wholesale suite where by specific rules are not working, and i've had no luck contacting the developers.

So i'm looking for a workaround to my problem.

On my store a particular product has a set minimum order quantity of 3, now an alert error is shown if the user has less than 3 in their basket however the plugin is still allowing users to check out even if they have less than 3 of the product in the basket.

So i was wondering if there is a way to disable the checkout button if their is an error message displayed on the checkout page?

the error message is

<ul  role="alert">
    <li>
        Your current order quantity total of Remedi Gin – 5cl is 2 — the minimum quantity you can order is 3
    </li>
</ul>

and the button code is

<a href="https://www.mysite.co.uk/checkout/" >
Proceed to checkout</a>

is there a way to disable the button if the error message is displayed and enable it if there is no error message displayed?

Many Thanks for your time

CodePudding user response:

Use Below script at the end of your page and pass your quantity field instead of 'you quantity field'

     <script> 
  $(".checkout-button").click(function(event){
            
      if($('your quantity field') < 3)
    {  
     $('.checkout-button').attr('disabled',true);
                event.preventDefault();  
     }else {   
    $('.checkout-button').attr('disabled',false);   
    } 
    }); 
         </script>

CodePudding user response:

Try this

<script>
   setInterval(()=>{
      if($('.woocommerce-error').children.length>0){
         $(.checkout-button).attr('disabled',true);
      }else{
         $(.checkout-button).attr('disabled',false);
      }
   },3000) // this will check if there any error every 3 sec
</script>
  • Related