Get the order ID in checkout page before payment process

后端 未结 3 1834
南旧
南旧 2020-12-18 16:38

In WooCommerce, I need to get order ID right in checkout page of WooCoommerce, before payment, when the order is created.

3条回答
  •  醉酒成梦
    2020-12-18 17:31

    so unfortunately you cannot access the order_id on the checkout page itself because the order has not been created yet. Though this is true, the cart data is temporarily saved as a 'session' as WooCommerce calls it. this may help you a bit with your issue with passing information to an iFrame if you can tweak it a bit.

    The way you can do this is by getting the information from the WC_session:

    $cart_data = WC()->session->get('cart');
    

    Once you do that, you will be able to access the cart data hierarchy as stored by WooCommerce by using a key index such as 'product_id' :

    $cart_data[array_keys($cart_data)[0]]['product_id'];
    

    Here is the list of valid cart data keys:

    key
    product_id
    variation_id
    variation (Array)
    quantity
    data_hash
    line_tax_data (Array)
    line_subtotal
    line_subtotal_tax
    line_total
    line_tax

提交回复
热议问题