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!
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’?
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!
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!