WC_Shortcode_Checkout::get_order_preselected_gateway
Get the gateway to pre-select on the pay page, when it should differ from the default selection.
A merchant assigns the method when creating an order in admin, so that assignment is the pre-selection. Orders placed through checkout carry the method the shopper picked, so those keep the default selection.
Method of the class: WC_Shortcode_Checkout{}
No Hooks.
Returns
WC_Payment_Gateway|null.
Usage
$result = WC_Shortcode_Checkout::get_order_preselected_gateway( $order, $available_gateways );
- $order(WC_Order) (required)
- Order being paid for.
- $available_gateways(WC_Payment_Gateway[]) (required)
- Gateways available on the pay page, keyed by gateway ID.
Changelog
| Since 11.3.0 | Introduced. |
WC_Shortcode_Checkout::get_order_preselected_gateway() WC Shortcode Checkout::get order preselected gateway code WC 11.3.0
private static function get_order_preselected_gateway( WC_Order $order, array $available_gateways ) {
if ( ! $order->is_created_via( 'admin' ) ) {
return null;
}
$payment_method = $order->get_payment_method();
return $payment_method && isset( $available_gateways[ $payment_method ] ) ? $available_gateways[ $payment_method ] : null;
}