I want to accomplish 2 things in my woocommerce checkout form: 1. Put some text between some groups of fields, for example (h3):
<h3>my custom heading</h3>
<p class="form-row form-row validate-required">
<input type="email">...
</p>
<h3>my other custom heading</h3>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
2. Display input tag first and label tag as second in html (woocommerce display label before input by default)
I figured out that checkout form is displayed by this code (for billing):
<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
How can I customize it in way I described?
I'm not sure on part 1, but for part 2, you can modify the output of
woocommerce_form_field()
by filteringwoocommerce_form_field_$type
.So your part 2 can be solved like so:
You would need to write a few more functions (mostly I copied and pasted whole swaths of code from WooCommerce and then just swapped the label part around ) for other other field types, but this should serve as an example.
For the first one you can do the following to display single input field
where you can replace
first_name
with any key of the checkout billing fieldsSo for your example it will be something like this
As for the second I'm not sure how you can achieve that. I needed something similar and i used javascript to reposition the labels.
something like :
As far as I think, woo commerce does not support html, there's a plugin known as woocommerce checkout field editor, see if it solves your issue.