AeliaWCEU_VAT_AssistantFrontend_Integration

Implements the integration with the frontend user interface.

Defined (1)

The class is defined in the following location(s).

/src/lib/classes/integration/frontend/frontend_integration.php  
  1. class Frontend_Integration extends \Aelia\WC\Base_Class { 
  2. protected static $instance; 
  3. protected $text_domain; 
  4.  
  5. public static function init() { 
  6. self::$instance = new self(); 
  7.  
  8. public function __construct() { 
  9. parent::__construct(); 
  10. $this->text_domain = WC_Aelia_EU_VAT_Assistant::$text_domain; 
  11. $this->set_hooks(); 
  12.  
  13. protected function EUVA() { 
  14. return WC_Aelia_EU_VAT_Assistant::instance(); 
  15.  
  16. /** 
  17. * Adds localisation data for the JavaScript used on the frontend. 
  18. * @param array $frontend_scripts_params The array of parameters to extend. 
  19. * @return array The array of parameters with additional data. 
  20. */ 
  21. //public static function localize_frontend_scripts(array $frontend_scripts_params) { 
  22. // $euva = WC_Aelia_EU_VAT_Assistant::instance(); 
  23. // 
  24. // $frontend_scripts_params['some_group'] = array( 
  25. // ); 
  26. // return $frontend_scripts_params; 
  27. //} 
  28.  
  29. protected function set_hooks() { 
  30. // My Account 
  31. add_action('woocommerce_billing_fields', array($this, 'woocommerce_billing_fields'), 10, 1); 
  32. add_action('woocommerce_my_account_my_address_formatted_address', array($this, 'woocommerce_my_account_my_address_formatted_address'), 10, 3); 
  33.  
  34. /** 
  35. * Shows additional fields in the My Account > Edit > Billing address section. 
  36. * @param array fields The array of fields to display. 
  37. * @return array The fields array, with extra fields added to it. 
  38. */ 
  39. public function woocommerce_billing_fields($fields) { 
  40. // Show the VAT number on the "My Account" page 
  41. if(is_account_page()) { 
  42.  
  43. $fields['vat_number'] = array( 
  44. 'label' => __('VAT Number', $this->text_domain),  
  45. 'placeholder' => _x('VAT Number', 'placeholder', $this->text_domain),  
  46. 'required' => false,  
  47. 'class' => array('form-row-first'),  
  48. 'clear' => false 
  49. ); 
  50. return $fields; 
  51.  
  52. /** 
  53. * Shows additional fields on the My Account > Billing address section. 
  54. * @param array fields The array of fields to display. 
  55. * @return array The fields array, with extra fields added to it. 
  56. */ 
  57. public function woocommerce_my_account_my_address_formatted_address($fields, $customer_id, $address_name) { 
  58. if(strcasecmp($address_name, 'billing') === 0) { 
  59. $fields['vat_number'] = get_user_meta($customer_id, Definitions::FIELD_VAT_NUMBER, true); 
  60. return $fields;