I need to add some info after each required fieds in Woocommerce checkout form. I'm using Wordpress 6.2.2 and WooCommerce 7.3.0 With this code I can add my info, but not for all required fields, e.g. 'billing_postcode', 'billing_city' still unchanged.
add_filter('woocommerce_form_field','wphelp_error_tag', 10, 4 );
function wphelp_error_tag( $field, $key, $args, $value ) {
if ( strpos( $field, '</label>' ) !== false && $args['required']) {
$error = '<span class="error" id="'.$key.'" style="display:none">';
$error .= sprintf( __( '%s is a required field.', 'woocommerce' ), $args['label'] );
$error .= '</span>';
$field = substr_replace( $field, $error, strpos( $field, '</label>' ), 0);
}
return $field;
}
I want to achieve this code
<label for="billing_postcode" class="">Postleitzahl
<abbr class="required" title="erforderlich">*</abbr>
<span class="error" style="display:none">
Vorname ist ein Pflichtfeld.</span></label>
Instead of standard:
<label for="billing_postcode" class="">Postleitzahl
<abbr class="required" title="erforderlich">*</abbr></label>
I found similar question here How to hook on a WooCommerce checkout field?, but I think that this info is obsolete.