Last active
April 2, 2016 05:57
-
-
Save blogjunkie/4712311 to your computer and use it in GitHub Desktop.
Display a custom message for WooCommerce subscription products in order complete email. Goes in your theme's functions.php or as a plugin. Credits: Patrick Garman (@pmgarman)
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 | |
/* Custom message for subscription products in order complete email */ | |
add_action( 'woocommerce_email_after_order_table', 'wc_completed_email_snippet' ); | |
function wc_completed_email_snippet( $order ) { | |
$order_statuses = array( 'completed' ); // order statuses to enable the email on | |
$display_cats = array( 148, 149 ); // cat ID's of products to display the message on completed emails for | |
if( in_array( $order->status, $order_statuses ) ) | |
return; // only completed orders | |
if( !class_exists( 'WC_Subscriptions_Order' ) || !class_exists( 'WC_Subscriptions_Renewal_Order' ) ) | |
return; // make sure subscriptions is installed and active | |
if( !WC_Subscriptions_Order::order_contains_subscription( $order ) ) | |
return; // is this a subscription order? | |
if( $order->post_parent > 0 ) | |
return; // if there is a post parent then this is a renewal | |
foreach( $order->get_items() as $item ) | |
foreach( wp_get_post_terms( $item['id'], 'product_cat' ) as $term ) | |
if( in_array( $term->term_id, $display_cats ) ) | |
$display = true; | |
if( $display ) | |
echo '<strong>A custom note</strong>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment