0
votes

WooCommerce Required field error message can be displayed below the checkout field. But I can't display the validation error message below the checkout field. Any solution please ....

 function checkout_validation_fields_error ( $field, $key, $args, $value ) {
if ( strpos( $field, '<span class="woocommerce-input-wrapper">' ) !== false && $args['woocommerce-invalid'] ) {
   $error = '<span class="error-inline" style="display:none">';
   $error .= sprintf( __( '%s <span class="error-inline-left" > is a not valid.</span>', 'woocommerce' ), $args['label'] );
   $error .= '</span>';
   $field = substr_replace( $field, $error, strpos( $field, '</span>' ), 0);
}

return $field; }

add_filter( 'woocommerce_form_field', 'checkout_validation_fields_error', 10, 4 );

enter image description here

1

1 Answers

0
votes

Change the $args['woocommerce-invalid'] to $args['required'] and it works.