WC_Checkout::process_order_payment()protectedWC 3.0.0

Process an order that does require payment.

Method of the class: WC_Checkout{}

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->process_order_payment( $order_id, $payment_method );
$order_id(int) (required)
Order ID.
$payment_method(string) (required)
Payment method.

Changelog

Since 3.0.0 Introduced.

WC_Checkout::process_order_payment() code WC 8.6.1

protected function process_order_payment( $order_id, $payment_method ) {
	$available_gateways = WC()->payment_gateways->get_available_payment_gateways();

	if ( ! isset( $available_gateways[ $payment_method ] ) ) {
		return;
	}

	// Store Order ID in session so it can be re-used after payment failure.
	WC()->session->set( 'order_awaiting_payment', $order_id );

	// We save the session early because if the payment gateway hangs
	// the request will never finish, thus the session data will neved be saved,
	// and this can lead to duplicate orders if the user submits the order again.
	WC()->session->save_data();

	// Process Payment.
	$result = $available_gateways[ $payment_method ]->process_payment( $order_id );

	// Redirect to success/confirmation/payment page.
	if ( isset( $result['result'] ) && 'success' === $result['result'] ) {
		$result['order_id'] = $order_id;

		$result = apply_filters( 'woocommerce_payment_successful_result', $result, $order_id );

		if ( ! wp_doing_ajax() ) {
			// phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
			wp_redirect( $result['redirect'] );
			exit;
		}

		wp_send_json( $result );
	}
}