Stefan Trailovic Stefan Trailovic - 3 months ago 9
Javascript Question

Prestasho hide/show payment method if VAT exists

I want to hide a payment method and show it only if customer has enterd a VAT number.
I have this code:

<input type="text" id="vat_number"/>
<a class="universalpay" title="Invoice">INVOICE PAYMENT</a>


JS

$(document).ready(function(){
$("a[title='Invoice']").hide();

$('#vat_number').keyup(function(){
if($(this).val().length !=0){
$("a[title='Invoice']").show();
}
else
{
$("a[title='Invoice']").hide();
}
})
});


But problem is that when someone press "Accept the terms & condition" it reloads the payment methods and then it shows agian.

How can i force it to hide until the VAT is filled?

Answer

You can use the ajaxComplete method:

$(document).ajaxComplete(function(){
    // Check if we are in order page
    if($('body').attr('id') == 'order'){
         if($('#vat_number').val().length != 0){
             $("a[title='Invoice']").show();
         } else {
             $("a[title='Invoice']").hide();
         }

    }
});