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

WooCommerce 在插件付款前獲取訂單產(chǎn)品詳細(xì)信息

WooCommerce Get Order Product Details Before Payment in Plugin(WooCommerce 在插件付款前獲取訂單產(chǎn)品詳細(xì)信息)
本文介紹了WooCommerce 在插件付款前獲取訂單產(chǎn)品詳細(xì)信息的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我需要在插件付款前顯示購物車中的訂單詳細(xì)信息.

I need to display order details from cart before payment in plugin.

我正在開發(fā)一個(gè)連接 woocommerce 和支付 API 的插件,在那里我需要發(fā)送一系列產(chǎn)品詳細(xì)信息,例如產(chǎn)品 ID、名稱、描述、數(shù)量和個(gè)人金額.

I work on one plugin what connect woocommerce and an payment API and there I need to send array of product details like product ID, name, description, quantity and individual amount.

我的問題是我找不到正確的鉤子來正確獲取所有數(shù)據(jù).

My problem is that I can't find right hook to get all data properly.

如何獲取這些數(shù)據(jù)?

謝謝

以下是針對(duì)需要它的每個(gè)人的答案的更新:

Here is update based on anwers for everyone who need it:

add_action('woocommerce_checkout_process', 'woocommerce_get_data', 10);
function woocommerce_get_data(){

        $cart = array();
        $items = WC()->cart->get_cart();
        foreach($items as $i=>$fetch){
            $item = $fetch['data']->post;

            $cart[]=array(
                'code'        => $fetch['product_id'], 
                'name'        => $item->post_title, 
                'description' => $item->post_content, 
                'quantity'    => $fetch['quantity'], 
                'amount'      => get_post_meta($fetch['product_id'], '_price', true)
            );
        }

        $user = wp_get_current_user();

        $data = array(
            'total' => WC()->cart->total,
            'cart'  => $cart,
            'user'  => array(
                'id' => $user->ID,
                'name' => join(' ',array_filter(array($user->user_firstname, $user->user_lastname))),
                'mail' => $user->user_email,
            )
        );

        $_SESSION['woo_data']=json_encode($data);

    }

感謝@loictheaztec 和@raunak-gupta

Thanks to @loictheaztec and @raunak-gupta

推薦答案

我認(rèn)為您正在尋找 woocommerce_checkout_process 掛鉤.WC_Checkout::process_checkout() – 在按下確認(rèn)訂單按鈕.

I think you are looking for woocommerce_checkout_process hook. WC_Checkout::process_checkout() – Process the checkout after the confirm order button is pressed.

代碼如下:

add_action('woocommerce_checkout_process', 'wh_getCartItemBeforePayment', 10);

function wh_getCartItemBeforePayment()
{
    $items = WC()->cart->get_cart();

    foreach ($items as $item => $values)
    {
        $_product = $values['data']->post;
        $product_title = $_product->post_title;
        $qty = $values['quantity'];
        $price = get_post_meta($values['product_id'], '_price', true);
    }
}

代碼位于活動(dòng)子主題(或主題)的 function.php 文件中.或者也可以在任何插件 php 文件中.

希望這有幫助!

這篇關(guān)于WooCommerce 在插件付款前獲取訂單產(chǎn)品詳細(xì)信息的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡(jiǎn)單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产黄色大片在线观看 | 一区视频在线免费观看 | 日韩一区二区三区视频在线播放 | 操久久 | 特级生活片| 中文字幕国产精品 | 亚洲h在线观看 | 91精品国产综合久久久久久丝袜 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 81精品国产乱码久久久久久 | 亚洲日本一区二区三区四区 | 亚州精品天堂中文字幕 | 91夜色在线观看 | 日韩一区在线播放 | 中文字幕第一页在线 | 国产一区中文 | 四虎永久免费在线 | 久久国产精品久久 | 日韩快播电影网 | 精品一区二区三区电影 | 91视视频在线观看入口直接观看 | 天天干天天爽 | 九九精品在线 | 秋霞影院一区二区 | 日韩中文一区二区三区 | 精精久久 | 亚洲视频在线观看 | 91看片视频 | 精品久久久久久久久久久久久久 | 亚洲一区在线播放 | 玖玖玖在线观看 | 亚洲精品一区在线观看 | 免费看黄色视屏 | 男人视频网站 | 狠狠干夜夜草 | 精品久久香蕉国产线看观看亚洲 | 国产一区二区欧美 | 日韩激情视频一区 | 久久久久国产成人精品亚洲午夜 | 久久久不卡网国产精品一区 | 亚洲精品国产第一综合99久久 |