WC_Payment_Gateways::init
Load gateways and hook in functions.
Method of the class: WC_Payment_Gateways{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Payment_Gateways = new WC_Payment_Gateways(); $WC_Payment_Gateways->init();
WC_Payment_Gateways::init() WC Payment Gateways::init code WC 10.5.0
public function init() {
$load_gateways = array(
'WC_Gateway_BACS',
'WC_Gateway_Cheque',
'WC_Gateway_COD',
'WC_Gateway_Paypal',
);
// Filter.
$load_gateways = apply_filters( 'woocommerce_payment_gateways', $load_gateways );
// Get sort order option.
$ordering = (array) get_option( 'woocommerce_gateway_order' );
$order_end = 999;
// Load gateways in order.
foreach ( $load_gateways as $gateway ) {
if ( is_string( $gateway ) && class_exists( $gateway ) ) {
$gateway = new $gateway();
}
if ( is_a( $gateway, 'WC_Gateway_Paypal' ) ) {
WC_Gateway_Paypal::set_instance( $gateway );
if ( ! $this->should_load_paypal_standard() ) {
continue;
}
}
// Gateways need to be valid and extend WC_Payment_Gateway.
if ( ! is_a( $gateway, 'WC_Payment_Gateway' ) ) {
continue;
}
if ( isset( $ordering[ $gateway->id ] ) && is_numeric( $ordering[ $gateway->id ] ) ) {
// Add in position.
$this->payment_gateways[ $ordering[ $gateway->id ] ] = $gateway;
} else {
// Add to end of the array.
$this->payment_gateways[ $order_end ] = $gateway;
++$order_end;
}
}
ksort( $this->payment_gateways );
add_action( 'wc_payment_gateways_initialized', array( $this, 'on_payment_gateways_initialized' ) );
/**
* Hook that is called when the payment gateways have been initialized.
*
* @param WC_Payment_Gateways $wc_payment_gateways The payment gateways instance.
* @since 8.5.0
*/
do_action( 'wc_payment_gateways_initialized', $this );
}