Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @jhonnwest,

    You can customize checkout field in a number of different ways using 3rd-party plugins or code.

    We recommend using a plugin to make these types of changes.

    Please refer to your documentation article: Customizing checkout fields and adding custom checkout fields.

    I’m closing this ticket for now. If you need further assistance related to this issue, simply reply to this message to re-open it.

    Best,
    Diego

    Thread Starter Jonathan

    (@jhonnwest)

    I customized the code below and it is applying the required field, but it is optional again. I have uploaded the gif file with the behavior: https://gifyu.com/image/Sh5wM

    add_filter( 'woocommerce_billing_fields', 'checkout_billing_fields', 9999 );
    add_filter( 'woocommerce_shipping_fields', 'checkout_shipping_fields' , 9999 );
    
    function checkout_billing_fields( $fields ) {
    
      if ( is_checkout() ) {
        if ( isset( $fields['billing_neighborhood'] ) ) {
          $fields['billing_neighborhood']['required'] = true;
        }
      }
      return $fields;
    }
    
    function checkout_shipping_fields( $fields ) {
      if (is_checkout() ) {
        if ( isset( $fields['shipping_neighborhood'] ) ) {
          $fields['shipping_neighborhood']['required'] = true;
        }
      }
      return $fields;
    }
    
    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @jhonnwest,

    The issue is probably related to the use of the conditional if ( is_checkout() ). This function will not detect requests made via AJAX which are used to update the checkout parts, including many checkout fields.

    You would probably want to remove that conditional as the fields should be set as required.

    Otherwise, you can use the function FluidCheckout_Steps::instance()->is_checkout_page_or_fragment() introduced with the latest version of Fluid Checkout Lite (2.1.0).

    Below is the code using the conditional with the function mentioned:

    add_filter( 'woocommerce_billing_fields', 'fluidcheckout_checkout_billing_fields', 9999 );
    add_filter( 'woocommerce_shipping_fields', 'fluidcheckout_checkout_shipping_fields' , 9999 );
    
    function fluidcheckout_checkout_billing_fields( $fields ) {
    
      if ( class_exists( 'FluidCheckout_Steps' ) && FluidCheckout_Steps::instance()->is_checkout_page_or_fragment() ) {
        if ( isset( $fields['billing_neighborhood'] ) ) {
          $fields['billing_neighborhood']['required'] = true;
        }
      }
      return $fields;
    }
    
    function fluidcheckout_checkout_shipping_fields( $fields ) {
      if ( class_exists( 'FluidCheckout_Steps' ) && FluidCheckout_Steps::instance()->is_checkout_page_or_fragment() ) {
        if ( isset( $fields['shipping_neighborhood'] ) ) {
          $fields['shipping_neighborhood']['required'] = true;
        }
      }
      return $fields;
    }

    I also changed the hooked function names to avoid conflicts with other components which might be adding functions with the same name.

    I hope this helps already.

    I’m closing this topic for now. If you need further assistance just reply to it.

    Best,
    Diego.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change fields style’ is closed to new replies.