久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在付款過程之前在結帳頁面中獲取訂單 ID

Get the order ID in checkout page before payment process(在付款過程之前在結帳頁面中獲取訂單 ID)
本文介紹了在付款過程之前在結帳頁面中獲取訂單 ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 WooCommerce 中,我需要在創建訂單時訂單 ID 在付款前在 WooCoommerce 的結帳頁面中獲得正確的信息.

我查看了所有會話,并試圖在 order_awaiting_payment 會話中找出訂單何時付款,但我在付款前需要它.
所以我想到了一個解決方案,即在結賬頁面加載時下訂單(實際上是準備付款),并在結賬真正完成時更新它.

如何在 WooCommerce 中的訂單付款之前在結帳頁面中獲取訂單 ID?

我認為有一些鉤子,但我找不到.

解決方案

您可以使用掛接在 woocommerce_checkout_order_processed 動作掛鉤.
由于woocommerce 3.0+版本,這里是位于process_checkout() 函數.

//從 WooCommerce 3.0+ 版本開始do_action('woocommerce_checkout_order_processed', $order_id, $posted_data, $order );

及以下 WooCommerce 3.0 版本:

//從 WooCommerce 2.1+ 版開始(3.0+ 版之前)do_action('woocommerce_checkout_order_processed', $order_id, $this->posted );

因此有兩種情況取決于您使用的 woocommerce 版本:

<塊引用>

從 WooCommerce 3.0+ 開始,您可以在掛鉤函數中使用 2 個額外的參數并且您將無需創建訂單對象的實例$order 已經作為參數.
您還可以通過 $posted_data 參數直接訪問發布的數據.

add_action('woocommerce_checkout_order_processed', 'action_checkout_order_processed', 10, 3);函數 action_checkout_order_processed( $order_id, $posted_data, $order ) {//做一點事}

<塊引用>

自 WooCommerce 2.1+ (WooCommerce 3.0 之前),您只有 $order_id 作為參數,因此您可能需要使用 $order 對象的實例.html" rel="noreferrer">wc_get_order() 函數:

add_action('woocommerce_checkout_order_processed', 'action_checkout_order_processed', 10, 1);函數 action_checkout_order_processed( $order_id ) {//獲取訂單對象的實例$order = wc_get_order( $order_id );//做一點事}

代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.

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

I look at all sessions and tried to find out when order goes for payment in order_awaiting_payment session, but I need it before going for payment.
So I think about a solution that is make order when checkout page loaded (In fact make it ready for payment) and when checkout real complete update it.

How to get order ID in checkout page before order go for payment in WooCommerce?

I think there is some hook for this but I can't find it.

解決方案

You can use a custom function hooked in woocommerce_checkout_order_processed action hook.
Since woocommerce 3.0+ version, here Is the corresponding core code located in process_checkout() function.

// Since WooCommerce version 3.0+
do_action( 'woocommerce_checkout_order_processed', $order_id, $posted_data, $order );

and below WooCommerce 3.0 version:

// Since WooCommerce version 2.1+ (before version 3.0+)
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );

So there is 2 cases depending which version of woocommerce you are using:

Since WooCommerce 3.0+ you can use 2 additional arguments in your hooked function and you will not need to create an instance of the order object as you get $order already as an argument.
You will be able also to access the posted data directly through $posted_data argument.

add_action('woocommerce_checkout_order_processed', 'action_checkout_order_processed', 10, 3);
function action_checkout_order_processed( $order_id, $posted_data, $order ) {
   // Do something
}

Since WooCommerce 2.1+ (Before WooCommerce 3.0), you have only the $order_id as argument, so you might be need to get an instance of $order object with wc_get_order() function:

add_action('woocommerce_checkout_order_processed', 'action_checkout_order_processed', 10, 1);
function action_checkout_order_processed( $order_id ) {
   // get an instance of the order object
   $order = wc_get_order( $order_id );

   // Do something
}

The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

這篇關于在付款過程之前在結帳頁面中獲取訂單 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 中国一级毛片免费 | 成人视屏在线观看 | 影音先锋中文字幕在线观看 | 国产精品视频一区二区三区 | 欧美一区二区三区在线视频 | 国产一区二区三区四区在线观看 | 91精品一区二区 | 91啪亚洲精品 | 在线看一区二区 | 精品一区二区三区中文字幕 | 精品欧美乱码久久久久久1区2区 | 久久精品国产精品青草 | 一级一片在线观看 | 国产一区二区精品在线观看 | 九九久久精品 | 五月激情综合网 | 91精品国产乱码久久久久久 | 欧美a级成人淫片免费看 | 久久91精品 | 欧美日韩精品综合 | 欧美 日韩 亚洲91麻豆精品 | 久久国产精品视频 | 精品在线 | 久久九九色 | 免费黄色片在线观看 | 狠狠干网 | 亚洲国产精品久久久久婷婷老年 | 国产精品高清一区二区 | 亚洲二区视频 | 亚洲成人日韩 | 亚洲成人一区二区 | 色综合久久天天综合网 | 午夜欧美日韩 | 亚洲自拍一区在线观看 | 国产91丝袜在线播放 | 91视频在线看 | 精品99久久久久久 | 成人h动漫亚洲一区二区 | 中文二区 | 国产乱码久久久 | 久久久精品国产 |