• Resolved ioankoul

    (@ioankoul)


    I had custom code in my theme’s functions.php to change the default classes for checkout fields using the woocommerce_checkout_fields filter.
    After updating to woocommerce 4.4 the classes are not correct for all ‘address’ fields.

    I was able to find a workaround for this problem, I changed the classes for name, surname, email, phone & country using woocommerce_checkout_fields, and the classes for address_1, address_2, city, state, postcode using the woocommerce_default_address_fields filter.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Just to clarify: you have gotten your custom code working with your workaround, so everything is OK here?

    I tried setting a custom class on the billing_address_1 field with the woocommerce_checkout_fields filter, and it seemed to work without any issues still:

    
    function my_custom_checkout_fields( $checkout_fields ) {
        $checkout_fields["billing"]["billing_address_1"]["class"][] = "my_custom_class";
    
        return $checkout_fields;
    }
    add_filter( 'woocommerce_checkout_fields', 'my_custom_checkout_fields', 10, 2 );
    

    Please let me know if you are still having any trouble here. If you have things working with your workaround though, then that’s great!

    Thread Starter ioankoul

    (@ioankoul)

    I managed to make it work with my workaround (using the ‘woocommerce_default_address_fields’ filter, but using the ‘woocommerce_checkout_fields’ filter won’t work.

    I just realized that I can add a custom class like ‘my_custom_class’ using the ‘woocommerce_checkout_fields’ filter but if I add the class ‘form-row-first’ for example it won’t add it. I believe theres JS envolved that removes the class.

    Can you try using the same code you sent me but with a class like ‘form-row-first’ or ‘form-row-last’?

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Thanks for the additional information here! Yep, it looks like custom classes can be added with the woocommerce_checkout_fields filter, however those default ones like the form-row-first / form-row-last / form-row-wide still take precedence and can’t be overridden / removed with that filter.

    Taking a look in the code, I see this mention of the woocommerce_default_address_fields filter:

    
    /**
     * Important note on this filter: Changes to address fields can and will be overridden by
     * the woocommerce_default_address_fields. The locales/default locales apply on top based
     * on country selection. If you want to change things like the required status of an
     * address field, filter woocommerce_default_address_fields instead.
     */
    

    So it seems using the woocommerce_default_address_fields filter is the way to go with customizing those attributes on the address fields at Checkout.

    Since you already have that set up and working, hopefully that will do the job for you!

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    We haven’t heard back from you in a while, so I’m going to mark this thread as resolved. If you have any further questions, please start a new thread.

    Have a wonderful day!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Checkout fields classes don’t work correctly after update’ is closed to new replies.