如何通过 ID 检查 WooCommerce 订单的付款方式? [英] How to check payment method on a WooCommerce order by id?

查看:20
本文介绍了如何通过 ID 检查 WooCommerce 订单的付款方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择的付款方式是货到付款,我想进行一些更改.在我使用过的现有 WC_Order 上

I want to make some changes if the chosen payment method is COD. On existing WC_Order i have used

($order->payment_method_title == 'Cash On Delivery' ? ... : ... );

检索标题.但我想检查 id (cod),因为标题字符串被翻译成不同的语言,这并不是一个好的解决方案.

to retrieve the title. But i would like to check against the id (cod) because the title string gets translated to different languages which doesn't make it a good solution.

有没有办法在 woocommerce 中检索 WC_Order 上的 id?

Is there a way to retrieve the id on a WC_Order in woocommerce?

推荐答案

支付方式 ID 的 post 元键很简单 _payment_method

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

因此,如果 $order->payment_method 没有到位的魔法方法来自动获取它,您可以使用传统的 WordPress 检索帖子元数据

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

WooCommerce 3.0 更新

$order->get_payment_method();

这篇关于如何通过 ID 检查 WooCommerce 订单的付款方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆