Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag Default WordPress and WooCommerce Emails #49

Open
bhubbard opened this issue May 15, 2019 · 3 comments
Open

Tag Default WordPress and WooCommerce Emails #49

bhubbard opened this issue May 15, 2019 · 3 comments

Comments

@bhubbard
Copy link
Contributor

I would love it if we could have all the default emails get Postmark Tag Support. So for example the New User Email could get a tag like 'wp-new-user' or something similar to that. Here is a good list I found of all the default WordPress emails.

https://github.com/johnbillion/wp_mail

Being able to filter these emails by tags in Postmark would be extremely useful.

@bhubbard
Copy link
Contributor Author

bhubbard commented Sep 8, 2020

@pgraham3 I have a snippet that will tag to WooCommerce Emails. Not sure where best to place the code in the plugin.

/**
 * Postmark Headers for WooCommerce.
 *
 * @param  [type] $headers  Headers.
 * @param  [type] $email_id Email ID.
 * @param  [type] $order    Order.
 */
function postmark_headers_for_woocommerce( $headers, $email_id, $order ) {

	$order_id = $order->get_order_number() ?? '';

	if ( ! empty( $order_id ) ) {
		$headers .= 'X-PM-Metadata-order-id: ' . $order_id . "\r\n";
	}
		$headers .= 'X-PM-Tag: woocommerce_' . $email_id . "\r\n";

	return $headers;
}

add_filter( 'woocommerce_email_headers', 'postmark_headers_for_woocommerce', 10, 3 );

@bhubbard
Copy link
Contributor Author

bhubbard commented Sep 8, 2020

Here is one for Gravity Forms:

/**
 * [postmark_headers_for_gravityforms description]
 * @param  [type] $email          [description]
 * @param  [type] $message_format [description]
 * @param  [type] $notification   [description]
 * @return [type]                 [description]
 */
function postmark_headers_for_gravityforms( $email, $message_format, $notification, $entry ) {

	$entry_id = $entry['id'] ?? '';
	$form_id = $entry['form_id'] ?? '';

	if( $entry_id ) {
		$email['headers']['X-PM-Metadata-gf-entry-id'] = 'X-PM-Metadata-gf-entry-id: ' . $entry_id;
	}

	if( $form_id ) {
		$email['headers']['X-PM-Metadata-gf-form-id'] = 'X-PM-Metadata-gf-form-id: ' . $form_id;
	}

	$email['headers']['X-PM-Tag'] = 'X-PM-Tag: gravity-forms';

	 return $email;

}

add_filter( 'gform_pre_send_email', 'postmark_headers_for_gravityforms', 10, 4 );

@pgraham3
Copy link
Contributor

pgraham3 commented Sep 9, 2020

@bhubbard Love the idea.

We don't want to be forcing default tags for anyone but I do think the plugin should support adding a Tag in general. Then you could use your filters above to set the X-PM-Tag header you wish to use and it will be present on the sent email.

Can you give this PR a try and let me know if it meets your needs for setting a Tag for your messages?

#67

After this looks good we can look into adding metadata support as well, which will be a bit more effort since the key for the metadata headers is variable (though it always starts with X-PM-Metadata-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants