admin管理员组文章数量:1323200
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.
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.
Share Improve this question asked Sep 30, 2020 at 12:24 Kia AbdiKia Abdi 33 bronze badges1 Answer
Reset to default 0I 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/reference/functions/__/
本文标签: pluginsChanging wordpresswoocommerce notices default message to other languages (text)
版权声明:本文标题:plugins - Changing wordpresswoocommerce notices default message to other languages (text) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090988a2420266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论