0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.