1
votes

Maybe you can give me a hand with this problem. I need to remove the bank account information (BACS) from the new order email if the client select to pay with credit card and leave it if they select direct bank transfer. Right now the info appears in both emails. (Credit payment and direct transfer). I'm using this code:

// Add your own action for the bank instructions
 add_action( 'woocommerce_email_before_order_table', 
 'prefix_email_instructions', 9, 3 );
 function prefix_email_instructions( $order, $sent_to_admin, $plain_text = 
 false ) {
// Get the gateway object
$gateways           = WC_Payment_Gateways::instance();
$available_gateways = $gateways->get_available_payment_gateways();
$gateway            = isset( $available_gateways['bacs'] ) ? 
 $available_gateways['bacs'] : false;

// We won't do anything if the gateway is not available
if ( false == $gateway ) {
    return;
}

// Add only the email instructions
if ( ! $sent_to_admin && 'bacs' === $order->payment_method && $order- 
>has_status( 'on-hold' ) ) {
    if ( $gateway->instructions ) {
        echo wpautop( wptexturize( $gateway->instructions ) ) 
. PHP_EOL;
    }
}
}

// Remove the original bank details
add_action( 'init', 'prefix_remove_bank_details', 100 );
function prefix_remove_bank_details() {

// Do nothing, if WC_Payment_Gateways does not exist
if ( ! class_exists( 'WC_Payment_Gateways' ) ) {
    return;
}

// Get the gateways instance
$gateways           = WC_Payment_Gateways::instance();

// Get all available gateways, [id] => Object
$available_gateways = $gateways->get_available_payment_gateways();

if ( isset( $available_gateways['bacs'] ) ) {
    // If the gateway is available, remove the action hook
    remove_action( 'woocommerce_email_before_order_table', array( 
$available_gateways['bacs'], 'email_instructions' ), 10, 3 );
}
}

But the info is still there. Any idea how to solve this?

1
Usless edition from @mujuonly. Just change some capital letters and delete the "thank you" at the end? :PFran
Would you like to revert it back?mujuonly
No mate, but its quite useless edition. I can understand if you or anybody else edit the code or something usefull but not a couple of capital letters and remove the "Thank you" at the end of my post. (Just good manners between somebody asking for help, and somebody be willing to help). :)Fran
Please check below answermujuonly

1 Answers

1
votes

This line of code is enough for that. It will unset the account details from the mail.

add_filter('woocommerce_bacs_accounts', '__return_false');