How to check payment method on a WooCommerce order by id?

核能气质少年 提交于 2019-12-02 18:18:27

The post meta key for the payment method ID is simply _payment_method

So if $order->payment_method doesn't have the magic methods in place to get that automatically, you could retrieve the post meta using traditional WordPress

get_post_meta( $order->id, '_payment_method', true );

Update for WooCommerce 3.0

$order->get_payment_method();

If you need the payment gateway object itself you can use the wc_get_payment_gateway_by_order function.

$payment_gateway = wc_get_payment_gateway_by_order( $order );

2019 now, if you want the title of the payment method you can do:

$order = new WC_Order( $order_id );
$payment_title = $order->get_payment_method_title();

This returns the string set in the Woocommerce > Payment methods, ex: Paypal.

Cheers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!