• Resolved kontur

    (@kontur)


    The plugin currently generates markup that has a wrapper with id=”vat_number_field” and inside it the actual field with id=”vat_number_field”, which, needless to say, messes up a good deal of things.

    Together with the lack of integration to regular WC checkout fields currently makes this plugin pretty hard to integrate to anything much.

Viewing 1 replies (of 1 total)
  • Plugin Author Diego

    (@daigo75)

    The duplicate ID is a glitch of which we are aware. We are making changes to use the billing_fields filter, that was an unintended side effect of the temporary changes we made. You already pointed out the lack of integration with the regular checkout fields some time ago. That has been noted and, as I already explained, it’s a work in progress. It’s not a mission critical issue, at the moment (in fact, we just received a couple of requests for that), which is why it took a low priority. Still, it’s going to be a breaking change, and we must be careful with its implementation.

    In the meantime, if you would like to add the VAT number field using the regular WC fields, you can do it with the following code (which is the same one that the EU VAT Assistant will use, for the same purpose):

    
    /**
     * Adds the VAT number field as part of the billing fields on the checkout page.
     * This function also moves the billing company just before the VAT number field.
     *
     * @param array fields
     * @return array
     */
    add_filter('woocommerce_checkout_fields', function($fields) {
      $text_domain = \Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::$text_domain;
      $current_user = wp_get_current_user();
      $settings = \Aelia\WC\EU_VAT_Assistant\WC_Aelia_EU_VAT_Assistant::settings();
    
      // Add the new VAT number field
      $fields['billing']['vat_number'] = array(
        'type'  => 'text',
        'default'  => is_object($current_user) ? $current_user->vat_number : '',
        'label' => '<strong>' . __('VAT number', $text_domain) . '</strong>',
        'placeholder' => __('VAT Number', $text_domain),
        'description' => __($settings->get('eu_vat_field_description'), $text_domain),
        'validate' => array(),
        'required' => false,
        'wrapper_class' => array('aelia_eu_vat_assistant checkout_field'),
        'class' => array('aelia_wc_eu_vat_assistant vat_number update_totals_on_change address-field form-row-wide'),
        'custom_attributes' => array(
          'valid' => 0,
        ),
        'priority' => 25,
      );
    
      return $fields;
    });
    
    /**
     * Removes the standard VAT Number field added by the EU VAT Assistant.
     *
     * @param bool show_vat_field
     * @param bool is_vat_field_required
     * @return bool
     */
    add_filter('wc_aelia_eu_vat_assistant_show_vat_field', function($show_vat_field, $is_vat_field_required) {
      return false;
    }, 10, 2);
    

    The plugin will identify the field on the checkout page and show/hide it as needed, like it does with the current one.

Viewing 1 replies (of 1 total)

The topic ‘Markup with double #id, missing WC form integration’ is closed to new replies.