wc_get_payment_gateway_by_order

Get payment gateway class by order data.

Description

(WC_Payment_Gateway|bool) wc_get_payment_gateway_by_order( (int|WC_Order) $order ); 

Returns (WC_Payment_Gateway|bool)

Parameters (1)

0. $order (int|WC_Order)
The order.

Usage

  1. if ( !function_exists( 'wc_get_payment_gateway_by_order' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The order. 
  5. $order = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_payment_gateway_by_order($order); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_get_payment_gateway_by_order( $order ) { 
  2. if ( WC()->payment_gateways() ) { 
  3. $payment_gateways = WC()->payment_gateways->payment_gateways(); 
  4. } else { 
  5. $payment_gateways = array(); 
  6.  
  7. if ( ! is_object( $order ) ) { 
  8. $order_id = absint( $order ); 
  9. $order = wc_get_order( $order_id ); 
  10.  
  11. return isset( $payment_gateways[ $order->get_payment_method() ] ) ? $payment_gateways[ $order->get_payment_method() ] : false;