@@ -63,12 +63,11 @@ protected static function maybe_skip_fieldset( $fieldset_key, $data ) {
6363 */
6464 public static function prepare_checkout_args ( $ input , $ context , $ info ) {
6565 $ data = array (
66- 'terms ' => (int ) isset ( $ input ['terms ' ] ),
67- 'createaccount ' => (int ) ! empty ( $ input ['account ' ] ),
68- 'payment_method ' => isset ( $ input ['paymentMethod ' ] ) ? $ input ['paymentMethod ' ] : '' ,
69- 'shipping_method ' => isset ( $ input ['shippingMethod ' ] ) ? $ input ['shippingMethod ' ] : '' ,
70- 'ship_to_different_address ' => ! empty ( $ input ['shipToDifferentAddress ' ] ) && ! wc_ship_to_billing_address_only (),
71- 'woocommerce_checkout_update_totals ' => isset ( $ input ['updateTotals ' ] ),
66+ 'terms ' => (int ) isset ( $ input ['terms ' ] ),
67+ 'createaccount ' => (int ) ! empty ( $ input ['account ' ] ),
68+ 'payment_method ' => isset ( $ input ['paymentMethod ' ] ) ? $ input ['paymentMethod ' ] : '' ,
69+ 'shipping_method ' => isset ( $ input ['shippingMethod ' ] ) ? $ input ['shippingMethod ' ] : '' ,
70+ 'ship_to_different_address ' => ! empty ( $ input ['shipToDifferentAddress ' ] ) && ! wc_ship_to_billing_address_only (),
7271 );
7372 $ skipped = array ();
7473
@@ -460,6 +459,11 @@ protected function process_order_without_payment( $order_id ) {
460459 $ order = wc_get_order ( $ order_id );
461460 $ order ->payment_complete ();
462461 wc_empty_cart ();
462+
463+ return array (
464+ 'result ' => 'success ' ,
465+ 'redirect ' => apply_filters ( 'woocommerce_checkout_no_payment_needed_redirect ' , $ order ->get_checkout_order_received_url (), $ order ),
466+ );
463467 }
464468
465469 /**
@@ -468,12 +472,11 @@ protected function process_order_without_payment( $order_id ) {
468472 * @param array $data Order data.
469473 * @param AppContext $context AppContext instance.
470474 * @param ResolveInfo $info ResolveInfo instance.
475+ * @param array $results Order status.
471476 *
472477 * @throws UserError When validation fails.
473478 */
474- public static function process_checkout ( $ data , $ context , $ info ) {
475- WC ()->session ->set ( 'refresh_totals ' , true );
476-
479+ public static function process_checkout ( $ data , $ context , $ info , &$ results = null ) {
477480 wc_maybe_define_constant ( 'WOOCOMMERCE_CHECKOUT ' , true );
478481 wc_set_time_limit ( 0 );
479482
@@ -491,26 +494,24 @@ public static function process_checkout( $data, $context, $info ) {
491494 // Validate posted data and cart items before proceeding.
492495 self ::validate_checkout ( $ data );
493496
494- if ( empty ( $ data ['woocommerce_checkout_update_totals ' ] ) ) {
495- self ::process_customer ( $ data );
496- $ order_id = WC ()->checkout ->create_order ( $ data );
497- $ order = wc_get_order ( $ order_id );
497+ self ::process_customer ( $ data );
498+ $ order_id = WC ()->checkout ->create_order ( $ data );
499+ $ order = wc_get_order ( $ order_id );
498500
499- if ( is_wp_error ( $ order_id ) ) {
500- throw new UserError ( $ order_id ->get_error_message () );
501- }
501+ if ( is_wp_error ( $ order_id ) ) {
502+ throw new UserError ( $ order_id ->get_error_message () );
503+ }
502504
503- if ( ! $ order ) {
504- throw new UserError ( __ ( 'Unable to create order. ' , 'wp-graphql-woocommerce ' ) );
505- }
505+ if ( ! $ order ) {
506+ throw new UserError ( __ ( 'Unable to create order. ' , 'wp-graphql-woocommerce ' ) );
507+ }
506508
507- do_action ( 'woocommerce_checkout_order_processed ' , $ order_id , $ data , $ order );
509+ do_action ( 'woocommerce_checkout_order_processed ' , $ order_id , $ data , $ order );
508510
509- if ( WC ()->cart ->needs_payment () ) {
510- self ::process_order_payment ( $ order_id , $ data ['payment_method ' ] );
511- } else {
512- self ::process_order_without_payment ( $ order_id );
513- }
511+ if ( WC ()->cart ->needs_payment () ) {
512+ $ results = self ::process_order_payment ( $ order_id , $ data ['payment_method ' ] );
513+ } else {
514+ $ results = self ::process_order_without_payment ( $ order_id );
514515 }
515516
516517 return $ order_id ;
0 commit comments