0

I have some code that let's you send an email once an item is back in stock. The email pulls the product link via a parameter %product_link% but I want to append to the end of the product link some UTM parameters so I am able to track visits from this link in GA.

Can someone help me on how I go about doing this?

The bit of code specific to the email is as follows:

// Options - Message
if ( get_option('Product_stock_option_message') ) {
    $options_message = get_option('Product_stock_option_message');
} else {
    $options_message = 'Hello, The product %product_name% is in stock. You can purchase it here: %product_link%';
}

$options_message = str_replace('%product_name%', $prod_title, $options_message);
$options_message = str_replace('%product_link%', $prod_link, $options_message);
Aaron Meese
  • 1,670
  • 3
  • 22
  • 32
kyarauk
  • 3
  • 4
  • I would probably modify `$prod_link` before running the `str_replace`. If you know the links don't already have query parameters, append `?utm_source=foo&utm_content=bar` – aynber Oct 14 '22 at 19:54
  • @aynber so like this? $prod_link = get_the_permalink($productId)?utm_source=foo&utm_content=bar; – kyarauk Oct 14 '22 at 20:00
  • No, you need to [concatenate the string](https://stackoverflow.com/questions/8336858/how-can-i-combine-two-strings-together-in-php) -- `$prod_link = get_the_permalink($productId)."?utm_source=foo&utm_content=bar";` – aynber Oct 14 '22 at 20:04
  • @aynber absolute genius! Thank you so much for your help. Tested and working as expected. – kyarauk Oct 14 '22 at 20:14

0 Answers0