Woocommerce /仅从已完成的订单中删除“付款说明”

时间:2019-10-25 11:16:18

标签: php wordpress woocommerce

最近2个小时,我一直在阅读有关此内容的文章,尝试使用不同的代码行,但没有一个完全符合我的意愿。

正如标题所述,我想从我的Woocommerce电子邮件中删除“付款说明”,但仅适用于“已完成的电子邮件”订单以及“付款方式”>“货到付款”和“银行转帐”!

我已经尝试过在此处的帖子中找到此代码。不幸的是,它不起作用。

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

我也尝试过这种方法,该方法有效,但适用于所有电子邮件。

add_action( 'woocommerce_email_before_order_table', function() {
    if( function_exists( 'wc_gateway_remove_hook' ) ) {
        wc_gateway_remove_hook( 'WC_Gateway_COD', 'woocommerce_email_before_order_table', 'email_instructions' );
    }
}, 10);

function wc_gateway_remove_hook( $classname, $hook, $callback ) {
    foreach( (array) $GLOBALS['woocommerce']->payment_gateways->payment_gateways as $key => $gateway_obj ) {
        if( $classname === get_class( $gateway_obj ) || 'customer_completed_order' === $email->id && 'cod' === $payment_method ) {
            remove_action( $hook, array( $gateway_obj, $callback ) );
        }
    }
}

我可以读懂php,但是我不是修改它的专家。 因此,欢迎其他任何代码构思!非常感谢。

1 个答案:

答案 0 :(得分:0)

试试这个货到付款:

function wc_gateway_remove_hook( $classname, $hook, $callback ) {
    foreach( (array) $GLOBALS['woocommerce']->payment_gateways->payment_gateways as $key => $gateway_obj ) {
        if( $classname === get_class( $gateway_obj ) || 'customer_completed_order' === $email->id && 'cod' === $payment_method ) {
            remove_action( $hook, array( $gateway_obj, $callback ) );
        }
    }
}
add_action( 'woocommerce_email_before_order_table', 'remove_instr_email_before_order_table_callback', 9, 4 );
function remove_instr_email_before_order_table_callback( $order, $sent_to_admin, $plain_text, $email ){
    $payment_method = $order->get_payment_method();
    if ( 'customer_completed_order' === $email->id && 'cod' === $payment_method ) {
        if( function_exists( 'wc_gateway_remove_hook' ) ) {
            wc_gateway_remove_hook( 'WC_Gateway_COD', 'woocommerce_email_before_order_table', 'email_instructions' );
        }
    }
}