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' ? ... : ... );
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.
Is there a way to retrieve the id on a WC_Order in woocommerce?
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 WordPressUpdate for WooCommerce 3.0
If you want the title of the payment method you can do:
This returns the string set in the Woocommerce > Payment methods, ex:
Paypal
.Here are some very helpful references and documentation that will help you do anything you want with WooCommerce.
Cheers.
If you need the payment gateway object itself you can use the
wc_get_payment_gateway_by_order
function.