• Resolved pinksharpii

    (@pinksharpii)


    I’ve followed this guide to create a new checkout field on a site https://developer.woocommerce.com/docs/cart-and-checkout-additional-checkout-fields/

    And it works great, the field was easily added to my checkout. But because the label is non-standard, the required validation message is a little awkward. I see the documentation provides instructions on how to add custom validation to ensure the value follows a specific format (Iike an email for example). But really what I’m looking to do is just change the wording of the required message, not add an additional format validation.

    Is this possible in the block checkout?

    It would also be great if we could add HTML before or after the field as well. But it sounds like that isn’t an option currently.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @pinksharpii ,

    Thanks for reaching out!

    I understand you’d like to customize the error message for a custom checkout field you created using the guide here: https://developer.woocommerce.com/docs/cart-and-checkout-additional-checkout-fields/#rendering-a-text-field

    Totally possible! WooCommerce supports adding your own validation and sanitization rules using WordPress action hooks. You can jump straight to the relevant section here: https://developer.woocommerce.com/docs/cart-and-checkout-additional-checkout-fields/#validation-and-sanitization

    Here’s a quick example that shows how you could add a custom error message when a field doesn’t meet certain criteria:

    add_action(
    'woocommerce_validate_additional_field',
    function ( WP_Error $errors, $field_key, $field_value ) {
    if ( 'namespace/gov-id' === $field_key ) {
    $match = preg_match( '/[A-Z0-9]{5}/', $field_value );
    if ( 0 === $match || false === $match ) {
    $errors->add( 'invalid_gov_id', 'Please ensure your government ID matches the correct format.' );
    }
    }
    },
    10,
    3
    );

    You can update this line to change the message:

    $errors->add( 'invalid_gov_id', 'Please ensure your government ID matches the correct format.' );

    Feel free to adjust the validation logic or the message to match your needs.

    I hope this helps!

    Thread Starter pinksharpii

    (@pinksharpii)

    That might work for custom sanitation validation but I’m trying to change the required text error message. Even with that hook it still displays the default required field text. “Please enter a valid when would you like to schedule your delivery or pickup?”

    So that doesn’t really work in this scenario.

    Hi @pinksharpii ,

    Thanks so much for reaching out!

    Could you walk us through how you added the field on your end? If you can share the steps you took, that’ll give us a clearer picture of what might be going on and help us point you toward the most relevant solution.

    Thread Starter pinksharpii

    (@pinksharpii)

    Yes these are the two hooks I have to create the field. It displays properly but the required field validation message does not display my custom message; it’s displaying the default required field text as seen in my initial screenshot.

    add_action(
    'woocommerce_init',
    function() {
    woocommerce_register_additional_checkout_field(
    array(
    'id' => 'vande/delivery_pickup_date',
    'label' => 'When would you like to schedule your delivery or pickup?',
    'location' => 'contact',
    'type' => 'text',
    'required' => true,
    ),
    );
    }
    );

    add_action(
    'woocommerce_validate_additional_field',
    function ( WP_Error $errors, $field_key, $field_value ) {
    if ( 'vande/delivery_pickup_date' === $field_key ) {
    if ( !$field_value ) {
    $errors->add( 'delivery_pickup_date', 'Please provide a pickup or delivery date option.' );
    }
    }
    },
    10,
    3
    );
    Zee

    (@doublezed2)

    Hello pinksharpii,

    Thank you for your reply.

    I understand you have created new checkout fields on your site using the developer documentation.

    Please note that the custom code falls outside our support policy scope. We may guide you with general direction but for more accurate guidanace I recommend you contact a professional developer. You can find a good developer at Codeable.io or WooExperts.

    Let me know if you have any questions.

    Have a great day!

    Plugin Support Kay U a11n

    (@kingsleyinfo)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    If you have a few minutes, we’d love if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/

    Thread Starter pinksharpii

    (@pinksharpii)

    I really don’t understand why this is out of scope of support.

    I’m using code in your documentation and it doesn’t work as expected. I can’t be the only one who has this issue of wanting to customize the error message for a required field that is left blank. Sure, there might not be a solution right now, but is this not something you would take to your developers as a feature request or bug fix?

    Hi there,

    I hear your frustration, and I really appreciate you sharing your thoughts on how you feel this should be handled.

    While we understand that the code in our documentation might not always meet every need, it’s important to note that this code is provided as-is, and we mention that in all advanced guides or developer-focused resources. We do our best to help with setup and general usage, but when it comes to code-level changes or extending default behavior, that falls under customization—which is outside our scope of support.

    Here’s the specific wording from our support policy:

    “We provide the Products as-is. While we can help you configure the Products within the capabilities of each extension or theme, we do not customize the Products or support any third-party customizations of the Products. Customization is anything that changes the way the Products look or function relative to how we make the Products available to you.

    If you need customization, we do our best to offer advice and direct you to appropriate resources. However, we do not take responsibility or endorse third-party solutions for customizing the Products. Third-party services that some customers have found helpful include Woo Agency Partners.”

    That said, if you believe this is a bug and not just a customization request, you’re welcome to report it directly to our developers here: https://github.com/woocommerce/woocommerce/issues

    Thanks again for your feedback—it helps us better understand the needs of our users.

    Zade

    (@nothin7)

    I just use CSS. For example, the Phone field:

    .wc-block-components-address-form__phone .wc-block-components-validation-error span {
    font-size: 0;
    }
    .wc-block-components-address-form__phone .wc-block-components-validation-error span:after {
    content: "A phone is needed in case of delivery issues";
    font-size: 12px;
    }
    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    Thanks for sharing your CSS approach 🙌 That can work as a quick visual fix.

    Just to note though, this doesn’t actually change the validation text at the source — it only hides the original and shows a new one with CSS. This means screen readers or translations won’t pick up the new message.

    If the goal is to properly replace the validation error text, it’s better to do it with a filter or translation method (for example, using Loco Translate or the gettext filter). That way, the text is changed consistently and will also work with multilingual sites.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘How to customize the required field text in the new block checkout?’ is closed to new replies.