从WooCommerce中的新订单电子邮件中删除银行帐户详细信息

时间:2019-04-03 00:28:21

标签: php wordpress woocommerce payment bank

也许您可以帮我解决这个问题。如果客户选择使用信用卡付款,我需要从新订单电子邮件中删除银行帐户信息(BACS),如果他们选择直接银行转帐,则将其保留。现在,该信息同时出现在两封电子邮件中。 (信用付款和直接转帐)。我正在使用以下代码:

// 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 );
}
}

但是信息仍然存在。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

这行代码就足够了。它将取消邮件中的帐户详细信息。

add_filter('woocommerce_bacs_accounts', '__return_false');