在WooCommerce获取信用卡支付的订单

问题描述 投票:1回答:1

在Woocommerce中,我试图通过信用卡获得所有付费订单,为此我尝试使用此代码:

// Get Report for orders made by credit card
foreach( $orders as $order ){
    if ( $order->get_payment_method() = 'nmwoo_2co' ) {
        $order_data = $order->get_data(); // The Order data
        $orders_by_credit .= 'Order Number: #' . $order->id . '<br>' .'Order Status: '. $order->status . '<br>' . 'Order Creation Date: ' . $order_date_created = $order_data['date_created']->date('Y-m-d H:i:s') . '<br>' . 'Order Total: '. $order->total . '<br>' . 'Customer Username: ' . $order_billing_first_name = $order_data['billing']['first_name'] . '<br>' . 'Customer E-Mail: '. $order_billing_email = $order_data['billing']['email'] . '<br>' . 'Customer Phone: ' . $order_billing_phone = $order_data['billing']['phone'] . '<br>' . $order->get_payment_method(); 
    }
}

但条件$orders->get_payment_method() = 'nmwoo_2co'不起作用。这是无效的,如何检查订单中使用的付款方式是否为nmwoo_2co?

php wordpress woocommerce hook-woocommerce orders
1个回答
1
投票

首先,你的IF语句中应该有一个错误(使用===而不是=):

if ( $order->get_payment_method() === 'nmwoo_2co' ) {

现在在您的代码中还有一些其他错误:

$orders_by_credit .= 'Order Number: #' . $order->id . '<br>' .'Order Status: '. $order->status . '<br>' . 'Order Creation Date: ' . $order_date_created = $order_data['date_created']->date('Y-m-d H:i:s') . '<br>' . 'Order Total: '. $order->total . '<br>' . 'Customer Username: ' . $order_billing_first_name = $order_data['billing']['first_name'] . '<br>' . 'Customer E-Mail: '. $order_billing_email = $order_data['billing']['email'] . '<br>' . 'Customer Phone: ' . $order_billing_phone = $order_data['billing']['phone'] . '<br>' . $order->get_payment_method(); 

那应该是:

$orders_by_credit .= 'Order Number: #' . $order->get_order_number() . '<br>' .'Order Status: '. $order->get_status() . '<br>' . 'Order Creation Date: ' . $order->get_date_created()->date('Y-m-d H:i:s') . '<br>' . 'Order Total: '. $order->get_total() . '<br>' . 'Customer Username: ' . $order->get_billing_first_name() . '<br>' . 'Customer E-Mail: '.  $order->get_billing_email() . '<br>' . 'Customer Phone: ' . $order->get_billing_phone() . '<br>' . $order->get_payment_method(); 

如何在WooCommerce中获取正确的付款ID:

  • 进入后端,在设置>付款时,当您点击付款方式时,您可以在URL中看到:?page=wc-settings&tab=checkout&section=paypal,其中paypal将针对每种付款方式更改为相应的付款方式ID slug。
  • 或者在结帐页面中,您可以使用浏览器工具检查value属性上的付款单选按钮,例如:value="paypal">

如果您设置了正确的付款IF,您的条件将有效。

见:How to get WooCommerce order details

© www.soinside.com 2019 - 2024. All rights reserved.