Magento – Make Tax/VAT number field required for orders more than x

orderstaxvat

Is it possible to make the Tax/VAT number field required in checkout page, if order total was more than x? How?

Thanks

Best Answer

You can achieve this with the following:

  1. Copy app/design/frontend/base/default/template/checkout/onepage/billing.phtml and/or app/design/frontend/base/default/template/checkout/onepage/shipping.phtml to your template folder

  2. add the check on the total value (subtotal, grand total,..) in the class attribute and change YOUR_TOTAL_AMOUNT to the total amount which you need as limit:

    <?php echo $this->getQuote()->getGrandTotal() >= YOUR_TOTAL_AMOUNT ? "required" : ""; ?>

The code of your input-form should look like this now:

<input type="text" 
 id="billing:vat_id"
 name="billing[vat_id]" 
 value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>" 
 title="<?php echo $this->__('VAT Number') ?>" 
 class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?> <?php echo $this->getQuote()->getGrandTotal() >= YOUR_TOTAL_AMOUNT ? "required" : ""; ?>" />

I didn't test it, but I think it should work #yolo.

Related Topic