Woocommerce: Get order id after checkout page [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-24 13:01:20

问题


I have purchased the Woocommerce Subscriptions plugin and i want to be able to get the order ID in checkout page. I want this, because when a subscription is about to end, an email with a payment link is sent to the customer and an order is automatically added. When customer clicks the link, it redirects to the checkout page in order to pay for the order. I need the order ID to retrieve meta data from the specific order using some function like wc_get_order_item_meta().


回答1:


You can get it like this:

    global $wp;
    $order_id = $wp->query_vars['order-pay'];
    $order = new WC_Order( $order_id );



回答2:


This is stored in the WC_Order class as a property. This means you can use:

WC()->order->id;



回答3:


Get an order at the checkout page, mmmm, don't think an order exists at this point, only a cart.



来源:https://stackoverflow.com/questions/33610832/woocommerce-get-order-id-after-checkout-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!