wc_get_payment_gateway_by_order()WC 2.2

Get payment gateway class by order data.

No Hooks.

Return

WC_Payment_Gateway|true|false.

Usage

wc_get_payment_gateway_by_order( $order );
$order(int|WC_Order) (required)
Order instance.

Changelog

Since 2.2 Introduced.

wc_get_payment_gateway_by_order() code WC 9.3.3

function wc_get_payment_gateway_by_order( $order ) {
	if ( WC()->payment_gateways() ) {
		$payment_gateways = WC()->payment_gateways()->payment_gateways();
	} else {
		$payment_gateways = array();
	}

	if ( ! is_object( $order ) ) {
		$order_id = absint( $order );
		$order    = wc_get_order( $order_id );
	}

	return is_a( $order, 'WC_Order' ) && isset( $payment_gateways[ $order->get_payment_method() ] ) ? $payment_gateways[ $order->get_payment_method() ] : false;
}