Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active September 20, 2017 10:28
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 webdados/b1963467b17313ba153eff6af286d537 to your computer and use it in GitHub Desktop.
Save webdados/b1963467b17313ba153eff6af286d537 to your computer and use it in GitHub Desktop.
Special Bank Transfer instructions for New Order emails no APG SMS (using the %bacs_instructions% tag on the sms template)
<?php
// Bank Transfer details
add_filter('apg_sms_message', 'apg_sms_message_bank_transfer', 999, 2);
function apg_sms_message_bank_transfer( $message, $order_id ) {
$inst = '';
$order = new WC_Order($order_id);
$status = is_callable( array( $order, 'get_status' ) ) ? $order->get_status() : $order->status; //WC >=3.0 or older?
//New order? (Not the English synthpop band...)
if ( $status == 'on-hold' || $status == 'pending' ) {
$payment_method = is_callable( array( $order, 'get_payment_method' ) ) ? $order->get_payment_method() : $order->payment_method; //WC >=3.0 or older?
if ( $payment_method=='bacs' ) {
if ( stristr( $message, '%bacs_instructions%' ) ) {
$inst = '';
$woocommerce_bacs_accounts = get_option( 'woocommerce_bacs_accounts' );
if ( is_array( $woocommerce_bacs_accounts ) ) {
foreach ( $woocommerce_bacs_accounts as $account ) {
$inst = '
IBAN '.trim($account['iban']).'
BIC/SWIFT '.trim($account['bic']).'
Val. '.( is_callable( array( $order, 'get_total' ) ) ? $order->get_total() : $order->order_total ).'
Please send payment receipt: email@email.com';
break; //Just the first bank account
}
}
}
}
}
//Replace the tag (for other payment methods $inst will be blank, which it's exactly what we want)
$message = str_replace( '%bacs_instructions%', $inst, $message );
//Clear unecessary spaces
$message = trim( preg_replace('/\s+/', ' ', $message) );
//Return it
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment