Title: PHP Warning: Undefined array key &#8220;order-pay&#8221;
Last modified: October 31, 2024

---

# PHP Warning: Undefined array key “order-pay”

 *  Resolved [bafna](https://wordpress.org/support/users/bafna/)
 * (@bafna)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/)
 * today i got this error in error_log
   [31-Oct-2024 14:22:27 UTC] PHP Warning: Undefined
   array key “order-pay” in public_html/wp-content/plugins/woocommerce/includes/
   class-wc-form-handler.php on line 412and then a customer buyed an product with
   out paying
 * after that i replaced the
 * public static function pay_action() {
   global $wp;
 *     ```wp-block-code
           if ( isset( $_POST['woocommerce_pay'], $_GET['key'] ) ) {
               wc_nocache_headers();
   
               $nonce_value = wc_get_var( $_REQUEST['woocommerce-pay-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
   
               if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-pay' ) ) {
                   return;
               }
   
               ob_start();
   
               // Pay for existing order.
               $order_key = wp_unslash( $_GET['key'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
               $order_id  = absint( $wp->query_vars['order-pay'] );
               $order     = wc_get_order( $order_id );
   
               if ( $order_id === $order->get_id() && hash_equals( $order->get_order_key(), $order_key ) && $order->needs_payment() ) {
   
                   do_action( 'woocommerce_before_pay_action', $order );
   
                   WC()->customer->set_props(
                       array(
                           'billing_country'  => $order->get_billing_country() ? $order->get_billing_country() : null,
                           'billing_state'    => $order->get_billing_state() ? $order->get_billing_state() : null,
                           'billing_postcode' => $order->get_billing_postcode() ? $order->get_billing_postcode() : null,
                           'billing_city'     => $order->get_billing_city() ? $order->get_billing_city() : null,
                       )
                   );
                   WC()->customer->save();
   
                   if ( ! empty( $_POST['terms-field'] ) && empty( $_POST['terms'] ) ) {
                       wc_add_notice( __( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce' ), 'error' );
                       return;
                   }
   
                   // Update payment method.
                   if ( $order->needs_payment() ) {
                       try {
                           $payment_method_id = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : false;
   
                           if ( ! $payment_method_id ) {
                               throw new Exception( __( 'Invalid payment method.', 'woocommerce' ) );
                           }
   
                           $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
                           $payment_method     = isset( $available_gateways[ $payment_method_id ] ) ? $available_gateways[ $payment_method_id ] : false;
   
                           if ( ! $payment_method ) {
                               throw new Exception( __( 'Invalid payment method.', 'woocommerce' ) );
                           }
   
                           $order->set_payment_method( $payment_method );
                           $order->save();
   
                           $payment_method->validate_fields();
   
                           if ( 0 === wc_notice_count( 'error' ) ) {
   
                               $result = $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 );
   
                                   wp_redirect( $result['redirect'] ); //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
                                   exit;
                               }
                           }
                       } catch ( Exception $e ) {
                           wc_add_notice( $e->getMessage(), 'error' );
                       }
                   } else {
                       // No payment was required for order.
                       $order->payment_complete();
                       wp_safe_redirect( $order->get_checkout_order_received_url() );
                       exit;
                   }
   
                   do_action( 'woocommerce_after_pay_action', $order );
   
               }
           }
       }
       ```
   
 * to this :
 * public static function pay_action() {
   global $wp;if ( isset( $_POST[‘woocommerce_pay’],
   $_GET[‘key’] ) ) {wc_nocache_headers();$nonce_value = wc_get_var( $_REQUEST[‘
   woocommerce-pay-nonce’], wc_get_var( $_REQUEST[‘_wpnonce’], ” ) ); // @codingStandardsIgnoreLine.
   if ( ! wp_verify_nonce( $nonce_value, ‘woocommerce-pay’ ) ) {return;}ob_start();//
   Pay for existing order.$order_key = wp_unslash( $_GET[‘key’] ); // phpcs:ignore
   WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
 *     ```wp-block-code
           if ( isset( $wp->query_vars['order-pay'] ) ) {        $order_id = absint( $wp->query_vars['order-pay'] );        $order = wc_get_order( $order_id );        if ( $order_id === $order->get_id() && hash_equals( $order->get_order_key(), $order_key ) && $order->needs_payment() ) {            do_action( 'woocommerce_before_pay_action', $order );            WC()->customer->set_props(array(                'billing_country'  => $order->get_billing_country() ? $order->get_billing_country() : null,                'billing_state'    => $order->get_billing_state() ? $order->get_billing_state() : null,                'billing_postcode' => $order->get_billing_postcode() ? $order->get_billing_postcode() : null,                'billing_city'     => $order->get_billing_city() ? $order->get_billing_city() : null,            ));            WC()->customer->save();            if ( ! empty( $_POST['terms-field'] ) && empty( $_POST['terms'] ) ) {                wc_add_notice( __( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce' ), 'error' );                return;            }            // Update payment method.            if ( $order->needs_payment() ) {                try {                    $payment_method_id = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : false;                    if ( ! $payment_method_id ) {                        throw new Exception( __( 'Invalid payment method.', 'woocommerce' ) );                    }                    $available_gateways = WC()->payment_gateways->get_available_payment_gateways();                    $payment_method     = isset( $available_gateways[ $payment_method_id ] ) ? $available_gateways[ $payment_method_id ] : false;                    if ( ! $payment_method ) {                        throw new Exception( __( 'Invalid payment method.', 'woocommerce' ) );                    }                    $order->set_payment_method( $payment_method );                    $order->save();                    $payment_method->validate_fields();                    if ( 0 === wc_notice_count( 'error' ) ) {                        $result = $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 );                            wp_redirect( $result['redirect'] ); //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect                            exit;                        }                    }                } catch ( Exception $e ) {                    wc_add_notice( $e->getMessage(), 'error' );                }            } else {                // No payment was required for order.                $order->payment_complete();                wp_safe_redirect( $order->get_checkout_order_received_url() );                exit;            }            do_action( 'woocommerce_after_pay_action', $order );        }    } else {        wc_add_notice( __( 'Order ID is missing. Please try again.', 'woocommerce' ), 'error' );        return;    }}}
       ```
   
 * but im still not sure if the code is right or not , please check if it will be
   fixed in the next updates or not , thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [bafna](https://wordpress.org/support/users/bafna/)
 * (@bafna)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/#post-18107695)
 * or maybe its this part ? idk
 * [31-Oct-2024 14:22:27 UTC] PHP Fatal error: Uncaught Error: Call to a member 
   function get_id() on bool in public_html/wp-content/plugins/woocommerce/includes/
   class-wc-form-handler.php:415 Stack trace: #0 public_html/wp-includes/class-wp-
   hook.php(324): WC_Form_Handler::pay_action() #1 public_html/wp-includes/class-
   wp-hook.php(348): WP_Hook->apply_filters() #2 public_html/wp-includes/plugin.
   php(565): WP_Hook->do_action() #3 public_html/wp-includes/class-wp.php(830): 
   do_action_ref_array() #4 public_html/wp-includes/functions.php(1336): WP->main()#
   5 public_html/wp-blog-header.php(16): wp() #6 public_html/index.php(17): require(‘…’)#
   7 {main} thrown in public_html/wp-content/plugins/woocommerce/includes/class-
   wc-form-handler.php on line 415
 *  [lukascech](https://wordpress.org/support/users/lukascech/)
 * (@lukascech)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/#post-18107724)
 * Woocommerce 9.3.3 started throwing out random fatal errors on my website, had
   to downgrade to 9.2.3:
 * [https://developer.woocommerce.com/releases/](https://developer.woocommerce.com/releases/)
 * try that and see if it helps. 
   Something’s fishy with WC 9.3.3
 *  Thread Starter [bafna](https://wordpress.org/support/users/bafna/)
 * (@bafna)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/#post-18107802)
 * thanks , i still wish for a fix update soon :)))
    -  This reply was modified 1 year, 7 months ago by [bafna](https://wordpress.org/support/users/bafna/).
 *  Plugin Support [shahzeen(woo-hc)](https://wordpress.org/support/users/shahzeenfarooq/)
 * (@shahzeenfarooq)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/#post-18109534)
 * Hi there!
 * Just to confirm, was your issue resolved after downgrading woocommerce to older
   version? I’m currently using WooCommerce 9.3.3 on my test site and haven’t encountered
   any fatal errors.
 * For testing, could you activate the default Storefront theme and only WooCommerce
   to check if the error still appears? To avoid affecting your live site, I recommend
   creating a staging environment, deactivating all plugins, and activating the 
   Storefront theme there.
 * For more details on running a conflict test, please refer to this guide: [How to Test for Conflicts](https://woocommerce.com/document/how-to-test-for-conflicts/).
 * 
    - **System Status Report** which you can find via WooCommerce > Status > Get
      system report > Copy for support.
    - **Fatal error logs** (if any) under WooCommerce > Status > Logs.
 * Once we have more information, we’ll be able to assist you further.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP Warning: Undefined array key “order-pay”’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [shahzeen(woo-hc)](https://wordpress.org/support/users/shahzeenfarooq/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/php-warning-undefined-array-key-order-pay/#post-18109534)
 * Status: resolved