Hi I’m kind of new to WordPress and right now I’m changing the notice message with filters and overwriting them inside functions.php. like this:
add_filter('woocommerce_lost_password_message', function () {
return 'My custom message';
});
or this one for coupon errors:
add_filter( 'woocommerce_coupon_error','coupon_error_message_change',10,3 );
function coupon_error_message_change($err, $err_code, $WC_Coupon) {
switch ( $err_code ) {
case $WC_Coupon::E_WC_COUPON_NOT_EXIST:
$err = 'Custom Message';
break;
case $WC_Coupon::E_WC_COUPON_ALREADY_APPLIED:
$err = 'Custom Message';
break;
case $WC_Coupon::E_WC_COUPON_EXPIRED:
$err = 'Custom Message';
break;
case $WC_Coupon::E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY:
$err = 'Custom Message';
break;
}
return $err;
}
But because I’m translating them to another language I need to change all of them.
is there any way that I can change the default text of the different notices and errors of woocommerce or WordPress all in once.
Maybe something like changing the main file of notices but without messing up the plugin code.
I’m trying to avoid repeating these filters for every notice inside website.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I think you should use wordpress string translation function __().
Like below:
add_filter('woocommerce_lost_password_message', function () {
return __('My custom message');
});
For more details
https://developer.wordpress.org/reference/functions/__/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0