Support » Plugin: WooCommerce » woocommerce_checkout_fields filter not working after form submit retur error

  • Hi,

    Ive written a new Gateway payment for Woocommerce and I have some additional fields.

    in the __construct method of my gateway class I call the filter:

    
    add_filter('woocommerce_checkout_fields', array(&$this, 'additional_fields'));
    

    and my method:

    
        public function additional_fields($fields) {
            
            $billing_birthdate = [
                'type' => 'text',
                'class' => array(
                'form-row form-row-first validate-required'
                ) ,
                'label' => 'Data de nascimento' ,
                'placeholder' => 'dd/mm/yyyy' ,
                'required' => true,
                
            ];
            
            $billing_document = [
                'type' => 'text',
                'class' => array(
                'form-row form-row-last validate-required'
                ) ,
                'label' => 'CPF' ,
                'placeholder' => '' ,
                'required' => true,
                
            ];
            
            $billing_address_number = [
                'type' => 'text',
                'class' => array(
                'form-row form-row-last validate-required'
                ) ,
                'label' => 'Número' ,
                'placeholder' => 'número' ,
                'required' => true,
                
            ];
            
            // colocar a data de nascimento depois do telefone
            $new_billing = array();
            
            foreach($fields['billing'] as $key => $value) {
                
                $new_billing[$key] = $value;
                
                if ($key == 'billing_phone') {
                    $new_billing['billing_birthdate'] = $billing_birthdate;
                    $new_billing['billing_document'] = $billing_document;
                }
                
                if ($key == 'billing_address_1') {
                    $new_billing['billing_address_1']['class'] = array(
                        'form-row form-row-first validate-required'
                    );
                    $new_billing['billing_address_number'] = $billing_address_number;
                }
                
            }
            
            $fields['billing'] = $new_billing;
            
            return $fields;
            
            
        }
    

    The issue:

    When the form is submitted, and pass through the javascript validation, but return errors after refreshing the page, the checkout fields filter is not applied and the custom fields disappear.

    Debugging, Ive notice that, in these cases, the filter is hooked before my gateway class adds it callback.

    Should the custom fields be outside the gateway class? Then I would need to check if this payment method is enabled…

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce_checkout_fields filter not working after form submit retur error’ is closed to new replies.