I want to use floating labels for the billing fields. Therefore I need to place the <label>
element after the <input>
field in the HTML structure.
At the moment my structure looks like this:
<p class="form-row form-row-first validate-required" id="billing_first_name_field" data-priority="10">
<label for="billing_first_name" class="">First Name <abbr class="required" title="required">*</abbr></label>
<span class="woocommerce-input-wrapper">
<input type="text" class="input-text form-control" name="billing_first_name" id="billing_first_name" placeholder="" value="First Name" autocomplete="given-name">
</span>
</p>
I want the label after the input/span element, like this:
<p class="form-row form-row-first validate-required" id="billing_first_name_field" data-priority="10">
<span class="woocommerce-input-wrapper">
<input type="text" class="input-text form-control" name="billing_first_name" id="billing_first_name" placeholder="" value="First Name" autocomplete="given-name">
</span>
<label for="billing_first_name" class="">First Name <abbr class="required" title="required">*</abbr></label>
</p>
Is there any way to change the output of the fields?
I found some hooks to change some elements of the fields: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
But that's all related the content of the elements. Not the HTML structure itself. Is that even possible?
$field
contains the complete<p>...</p>
output. So you can completely adjust the output. To keep it dynamic you can use the values from$args
See: https://github.com/woocommerce/woocommerce/blob/master/includes/wc-template-functions.php#L2830 and accompanying code, how to do this
function change_woocommerce_field_markup($field, $key, $args, $value) {
if( $key === 'billing_first_name') {
$field = 'my html';
}
return $field;
}
add_filter("woocommerce_form_field_text","change_woocommerce_field_markup", 10, 4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With