【问题标题】:Hide payment instructions from WooCommerce email completed order notifications从 WooCommerce 电子邮件中隐藏付款说明已完成的订单通知
【发布时间】:2019-10-12 13:11:42
【问题描述】:

在我的 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 );

它适用于所有电子邮件通知,我只需要从“客户完成订单”电子邮件通知中删除付款说明。

感谢任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce email-notifications payment-method


    【解决方案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 文件中。经过测试并且可以工作。

    【讨论】:

    • wooo 超级感谢您整天寻找解决方案,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 2017-05-05
    • 2016-06-11
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多