Advertisement
businessdad

EU VAT Assistant - Hide VAT number when company is empty

Nov 20th, 2017
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. /**
  2.  * Aelia EU VAT Assistant for WooCommerce - Show VAT number only when the company field is populated.
  3.  *
  4.  * Last updated: 5 August 2019
  5.  *
  6.  * HOW TO USE THIS CODE
  7.  * Simply add the code to the bottom of your theme's functions.php file, and it
  8.  * will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
  9.  *
  10.  * GPL DISCLAIMER
  11.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  12.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  13.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  14.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  15.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  16.  *
  17.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  18.  */
  19.  
  20. add_action('wp_footer', function() {
  21.   ?>
  22.   <script type="text/javascript">
  23.     jQuery(document).ready(function($) {
  24.       $('form.checkout, #order_review').on('change', function() {
  25.         var company_field_empty = ($('#billing_company').val().trim() == '');
  26.  
  27.         // Check if the company field is populated. If not, hide the VAT number
  28.         // field.
  29.         $('.aelia_wc_eu_vat_assistant.vat_number').toggle(!company_field_empty);
  30.  
  31.         // Uncomment the code below to clear the VAT number when the company
  32.         // name is emptied
  33.         //if(company_field_empty) {
  34.         //  $('#vat_number').val('');
  35.         //}
  36.       });
  37.     });
  38.   </script>
  39.   <?php
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement