Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save justinstern/7815673 to your computer and use it in GitHub Desktop.

Select an option

Save justinstern/7815673 to your computer and use it in GitHub Desktop.
Display any voucher numbers from voucher items in the order on the New Order admin email. To use this snippet simply paste into the bottom of your theme's functions.php
<?php
// Displays any voucher numbers on the New Order admin email
add_action( 'woocommerce_email_order_meta', function( $order, $is_admin ) {
if ( $is_admin ) {
$voucher_numbers = array();
$order_items = $order->get_items();
if ( count( $order_items ) > 0 ) {
foreach ( $order_items as $item ) {
if ( $item['product_id'] > 0 && isset( $item['voucher_id'] ) && $item['voucher_id'] ) {
$voucher = new WC_Voucher( $item['voucher_id'], $order->id, $item );
$voucher_numbers[] = $voucher->get_voucher_number();
}
}
}
echo "<p><strong>Email Certificate Number:</strong> " . implode( ', ', $voucher_numbers ) . "</p>";
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment