-2

Current issue: When a customer makes an order through Woocommerce, they receive an automated email with their purchased ticket number. However, the purchased ticket number is not in the correct format.

The email sends their ticket number as 'SECOND: 34', but there's no way within files/plugins etc I can change this. The best solution is to change in the email from 'SECOND: 34' to 'MIN: 0 SEC: 34', as an example.

Is there a way to dynamically upate/change strings within WooCommerce automated emails?

The only solution I can think of is to create a function that says if text is 'SECOND: 34' then display at as 'MIN: 0 SEC: 34'. I know this would require quite a lot of code to do, but it's the only workaround I can potentially think of. Thanks

I've tried locating the plugin files but cannot find anywhere that this allows for it. I'm hoping that I can create some code that automatically changes the output text in the email to be displayed as something else.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Ben
  • 1
  • 1
  • Your question is incomplete, so unclear, as you should mention what plugin you are using for those tickets in WooCommerce (and the related product settings)? Also we don't really know, where is located the text that you want to change on the email (you may provide those details and a screenshot). – LoicTheAztec Aug 08 '23 at 15:39

1 Answers1

0

If all you need is to replace a string with another string, you can use wp_mail filter

add_filter('wp_mail', 'abc_change_email_message', 10, 1);
function abc_change_email_message($args)
{
   if (
      strpos($args['message'], 'SECOND: 34') !== false
   ) {
      $args['message'] = str_replace('SECOND: 34', 'height="15" class="MIN: 0 SEC: 34', $args['message']);
   }

   return $args;
}

If you are trying to change a dynmaic string, you'll probably have to use regex.

Ali_k
  • 1,642
  • 1
  • 11
  • 20