Get current Order ID for Woocommerce user cart

Viewed 18441

I am adding a custom payment gateway to WP Woocommerce. I want to get the current user order_id for the cart created.

I can get the cart total :

global $woocommerce;
$total= $woocommerce->cart->total ;

or with :

WC()->cart->get_total() ;

How can I call the function :

process_payment($order_id)

when I don't have the $order_id yet and I have only the cart ?

(wrong question: there is no order_id yet)

5 Answers

The answer to the question asked initially is:

you don't have a Order ID yet in the cart. Only after checkout is complete the Order ID exists.

The answers are not inline with the question, which probably needs to be asked again or edited.

If you user tried a payment and it failed, you might like to check $order_id = WC()->session->get( 'order_awaiting_payment' );

Related