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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

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/reference/functions/__/

本文标签: pluginsChanging wordpresswoocommerce notices default message to other languages (text)