Created
May 11, 2025 15:01
-
-
Save imanuelgittens/6f287de689bc45ae5d6dbd223c4d321e to your computer and use it in GitHub Desktop.
Add Scotia's Required Information To WooCommerce's Default Email Templates
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 | |
/** | |
* Add Scotia Bank required order meta information to WooCommerce emails | |
* | |
* @author Imanuel Gittens | |
* | |
*/ | |
add_action( 'woocommerce_email_order_meta', 'wpcompanion_add_email_order_meta', 10, 3 ); | |
function wpcompanion_add_email_order_meta( $order, $sent_to_admin, $plain_text ){ | |
// this order meta checks if the order has an approval code | |
$approval_code = $order->get_meta( 'approval_code' ); | |
$order_id = $order->get_id(); | |
$currency_code = $order->get_currency(); | |
// we won't display anything if the order doesn't have an approval code | |
if( empty( $approval_code ) ) { | |
return; | |
} | |
// ok, if order has approval code we get the other fields. | |
$transaction_date = esc_html( $order->get_meta( 'txndatetime' ) ); | |
$card_info = esc_html( $order->get_meta( 'cardnumber' ) ); | |
// separate version for plaintext emails | |
if ( false === $plain_text ) { | |
// you shouldn't have to worry about inline styles, WooCommerce adds them itself depending on the theme you use | |
?> | |
<h2>Transaction Information</h2> | |
<ul> | |
<li><strong>Order ID:</strong> <?php echo $order_id ?></li> | |
<li><strong>Currency:</strong> <?php echo $currency_code ?></li> | |
<li><strong>Approval Code:</strong> <?php echo $approval_code ?></li> | |
<li><strong>Transaction Date:</strong> <?php echo $transaction_date ?></li> | |
<li><strong>Card Info:</strong> <?php echo $card_info ?></li> | |
</ul> | |
<?php | |
} else { | |
echo "\nTRANSATION INFORMATION\n" | |
. "Order ID: $order_id\n" | |
. "Currency Code: $currency_code\n" | |
. "Approval Code: $approval_code\n" | |
. "Transaction Date: $transaction_date\n" | |
. "Card Info: $card_info\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment