首页 > 解决方案 > 在添加操作以订购收到的电子邮件时,payment_method 调用不正确

问题描述

我正在使用此代码在接收到 woocommerce 发送的电子邮件的订单中显示其他信息。

add_action('woocommerce_email_after_order_table', 'add_order_email_instructions', 10, 2);

function add_order_email_instructions($order, $sent_to_admin) {

if (!$sent_to_admin) {

    if ( isset( $gateways['cod'] ) == $order->payment_method) {
        // cash on delivery method
        do_action('woocommerce_thankyou_lieferung', $order->get_id());
    } else {
        // other methods (ie credit card)

        do_action('woocommerce_thankyou_lieferung', $order->get_id());
    }
  }
}

这给了我错误信息

payment_method 调用不正确。不应直接访问订单属性。

在 debug.log 文件中

我找不到上面的代码有什么问题。

标签: methodswoocommercepayment

解决方案


add_action('woocommerce_email_after_order_table', 'add_order_email_instructions', 10, 2);

function add_order_email_instructions($order, $sent_to_admin) {

if (!$sent_to_admin) {

    if ( isset( $gateways['cod'] ) == $order->get_payment_method()) {
        // cash on delivery method
        do_action('woocommerce_thankyou_lieferung', $order->get_id());
    } else {
        // other methods (ie credit card)

        do_action('woocommerce_thankyou_lieferung', $order->get_id());
    }
  }
}

推荐阅读