Skip to content

Instantly share code, notes, and snippets.

@kilbot
Created April 13, 2023 12:56
Show Gist options
  • Save kilbot/e8d6753e842629572c8d07e0a7a83736 to your computer and use it in GitHub Desktop.
Save kilbot/e8d6753e842629572c8d07e0a7a83736 to your computer and use it in GitHub Desktop.
Changing default email template for POS orders
<?php
// This would go in your theme fucntions.php file, or you could create a new plugin
/**
* Change Email Subject and Heading
*/
function wc_custom_email_template_order_details( $order, $sent_to_admin, $plain_text, $email ) {
// If POS order, change the template
if ( $order->get_meta( '_pos' ) ) {
// Example: Change the email heading
$email->heading = 'Custom Email Heading';
// Example: Change the email subject
$email->subject = 'Custom Email Subject';
}
}
add_action( 'woocommerce_email_order_details', 'wc_custom_email_template_order_details', 10, 4 );
/**
* Change Before Order Table
*/
function wc_custom_email_template_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
if ( $order->get_meta( '_pos' ) ) {
echo '<p>Custom content before order table.</p>';
}
}
add_action( 'woocommerce_email_before_order_table', 'wc_custom_email_template_before_order_table', 10, 4 );
/**
* Change After Order Table
*/
function wc_custom_email_template_after_order_table( $order, $sent_to_admin, $plain_text, $email ) {
if ( $order->get_meta( '_pos' ) ) {
echo '<p>Custom content after order table.</p>';
}
}
add_action( 'woocommerce_email_after_order_table', 'wc_custom_email_template_after_order_table', 10, 4 );
/**
* Add Custom CSS Styles
*/
function wc_custom_email_template_styles( $css ) {
$css .= "
.custom-email-class {
font-weight: bold;
color: #f00;
}
";
return $css;
}
add_filter( 'woocommerce_email_styles', 'wc_custom_email_template_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment