Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could use the “wp_mail” filter, where the subject is passed to your callback. This fires before the email is sent, so you cannot know from here if the sending was successful or not. But what you could do is set the passed subject as a global variable in “wp_mail” that is later used in your dcart_line() callback.

    Yes, globals are considered bad form by some, but when your action hook doesn’t pass the data you need there’s not many good choices. You could set a static class property to avoid the nasty global. But it’s really just an obfuscated global without the stigma 🙂

    Thread Starter westham00

    (@westham00)

    Hi, thanks for your response. Sorry, I am quite new to this:

    You could use the “wp_mail” filter, where the subject is passed to your callback.

    How can I achieve this within my code block, I am assuming this filter comes directly underneath the function dcart_line() { , but when I add the wp_mail filter there is as an error. Thank you.

    Moderator bcworkz

    (@bcworkz)

    No need to apologize, we were all new to this at one point. At least you’ve then been spared the use of globals micro-controversy among coders 🙂

    The adding of “wp_mail” filter and its callback would be a completely separate code block. It can be in the same file, but not within your dcart_line() function. Don’t forget that in PHP a global variable must be declared both where it is assigned and where it is used.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Hook a variable’ is closed to new replies.