繁体   English   中英

隐藏WooCommerce电子邮件已完成订单通知中的付款说明

[英]Hide payment instructions from WooCommerce email completed order notifications

在我的woocommerce商店中,我已激活付款说明,并显示在所有电子邮件通知中。 我有以下代码(取自另一个答案) ,删除“COD”付款方式的付款说明:

add_action( 'woocommerce_email_before_order_table', function(){
    if ( ! class_exists( 'WC_Payment_Gateways' ) ) return;

    $gateways = WC_Payment_Gateways::instance(); // gateway instance
    $available_gateways = $gateways->get_available_payment_gateways();


    if ( isset( $available_gateways['cod'] ) )
        remove_action( 'woocommerce_email_before_order_table', array( $available_gateways['cod'], 'email_instructions' ), 10, 3 );
}, 1 );

它在全球范围内应用于所有电子邮件通知,我只需要从“客户已完成订单”电子邮件通知中删除付款说明。

任何帮助表示赞赏。

您的代码有点过时(或旧)并且您错过了钩子函数参数,这将允许您定位“客户已完成订单”电子邮件通知。 请尝试以下方法:

add_action( 'woocommerce_email_before_order_table', 'action_email_before_order_table_callback', 9, 4 );
function action_email_before_order_table_callback( $order, $sent_to_admin, $plain_text, $email ){
    $payment_method = $order->get_payment_method();

    // Targeting "COD" payment method on Customer completed order email notification
    if ( 'customer_completed_order' === $email->id && 'cod' === $payment_method ) {
        $available_gateways = WC()->payment_gateways->get_available_payment_gateways();

        remove_action( 'woocommerce_email_before_order_table', [ $available_gateways[$payment_method], 'email_instructions' ], 10 );
    }
}

代码位于活动子主题(或活动主题)的functions.php文件中。 经过测试和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM