Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/4a7d97fd58b262a1b1c97c4132d645ea to your computer and use it in GitHub Desktop.
Save damiencarbery/4a7d97fd58b262a1b1c97c4132d645ea to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Custom note to order email (for variation)
Plugin URI: https://www.damiencarbery.com/
Description: Add a note to the order email if the order contains products with a specific variation name.
Author: Damien Carbery
Version: 0.1
*/
/* Add note about electronic licenses to the order email. */
add_action( 'woocommerce_email_order_details', 'dcwd_electronic_license_info_to_order_email', 5, 4 );
function dcwd_electronic_license_info_to_order_email( $order, $sent_to_admin, $plain_text, $email ) {
// Only customers need to know about the delivery times.
if ( $sent_to_admin ) {
return;
}
$variation_name = 'White';
$order_has_specified_variation = false;
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
$product = $item->get_product();
if ( $product->is_type( 'variation' ) ) {
$variation_suffix = ' ' . $variation_name;
$variation_strlen = strlen( $variation_suffix );
if ( $variation_suffix == substr( $product->get_name(), -1 * $variation_strlen, $variation_strlen ) ) {
$order_has_specified_variation = true;
}
}
}
if ( $order_has_specified_variation ) {
if ( $plain_text ) {
echo "\nNOTE: This order has a product with the specified variation.\n";
}
else {
echo '<p><strong>Note</strong>: This order has a product with the specified variation.</p>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment