skip to Main Content

I am trying to modify the Woocomerce checkout page for orders that are failed or pending payment. On those orders the system comes to the checkout with an order already generated, but I am not able to retrieve the ID of that order from the form_checkout.php template.

Failed orders can be paid by the customer with the Woocommerce URL, similar to the following one:

https://myurl.com/checkout/order-pay/XXXXX/?pay_for_order=true&key=wc_order_XXXXXXXXXXXX&subscription_renewal=true

Neither do I retrieve the variables with a $_GET since the URL is transformed into https://myurl.com/checkout when accessing. I don’t know if you lose this data or where I can collect it.

Is this possible?

2

Answers


  1. To retrieve the order Id on Order pay page you will use the following:

    global $wp;
    
    if ( isset($wp->query_vars['order-pay']) && absint($wp->query_vars['order-pay']) > 0 ) {
        $order_id = absint($wp->query_vars['order-pay']); // The order ID
    
        $order    = wc_get_order( $order_id ); // Get the WC_Order Object instance
    }
    

    Note: To target Order pay page, you can use is_wc_endpoint_url('order-pay') conditional tag.

    Login or Signup to reply.
  2. $order = wc_get_order(get_query_var('order-pay'));

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search