Last active
December 12, 2023 04:49
-
-
Save nicomollet/1d0d1e80c4243644f444382658ce6968 to your computer and use it in GitHub Desktop.
Gravity Forms: Use WooCommerce emails templates for notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms: Use WooCommerce emails templates for notifications. | |
* | |
* @param string $template | |
* | |
* @return string | |
*/ | |
public function custom_gform_html_message_template_pre_send_email( string $template ) { | |
if ( function_exists( 'wc_get_template_html' ) && class_exists( 'WC_Email' ) ) { | |
$header = wc_get_template_html( | |
'emails/email-header.php', | |
array( | |
'email_heading' => '{subject}', | |
) | |
); | |
$footer = wc_get_template_html( 'emails/email-footer.php' ); | |
$wc_email = new WC_Email(); | |
$template = $wc_email->style_inline( $header . '{message}' . $footer ); | |
} | |
return $template; | |
} | |
add_filter( 'gform_html_message_template_pre_send_email', 'custom_gform_html_message_template_pre_send_email', 20, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the snippet!
I've made a simple improvement
WC_Email
class is not present until you initWC_Emails
class.