• I am trying to customize the checkout error message that appears when a user tries to submit the info without filling all the field, and it says” Billing First Name is a required field”

    Checkout error message

    I want to change the word” Billing” to another term.
    Which files do I need to edit to change this?

    I’ve already copied the Woocommerce files to my child theme directory to be safe when updating Woocommerce.

    Many thanks,
    Mamdouh

Viewing 7 replies - 1 through 7 (of 7 total)
  • Copying WooCommerce files to your child theme directory is not the recommended method for this problem. Consider using a filter as explained here:
    https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
    Your filter and function go in functions.php for your child theme.

    Thread Starter Mamdouh Kaldas

    (@elmalak)

    @lorro,

    Thanks for your help.

    I now see that this is the line of code I need to edit,

    $field_label = sprintf( _x( 'Billing %s', 'Billing FIELDNAME', 'woocommerce' ), $field['label'] );

    All I need is to replace the word Billing with another word, but I am not sure how to do this in the functions.php file.

    I’m sorry I gave a wrong answer. Its not functions.php for this.

    You’ll need to load Loco Translate:
    https://wordpress.org/plugins/loco-translate/
    “translate” includes using other words in the same language.

    Dashboard > Loco Translate > Plugins > WooCommerce > your-language > Edit
    Sync
    Filter for:
    Billing %s [Billing FIELDNAME]
    then in the translation box, change to your chosen words, eg:
    Charging %s
    Save

    If you have a custom template, the string might be at:
    Dashboard > Loco Translate > Themes > your-theme-name > your-language > Edit

    Hi,
    Add this code to your child theme’s functions.php and change Mybilling to whatever you want.

    function my_woocommerce_add_error( $error ) {
        return str_replace('Billing','Mybilling',$error);    
    }
    add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );
    Thread Starter Mamdouh Kaldas

    (@elmalak)

    @menakas

    Thank you so much that worked like a Charm.

    Thread Starter Mamdouh Kaldas

    (@elmalak)

    @lorro,
    Thank you for this suggestion, I will definitely give it a try as I am sure I will need to do more stuff like this again soon.

    Appreciate your care (:

    Hi @elmalak,
    Glad 🙂 Will you mark this post as resolved?

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

The topic ‘How Can I customize Checkout error message?’ is closed to new replies.