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

WooCommerce 在插件付款前獲取訂單產品詳細信息

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

問題描述

限時送ChatGPT賬號..

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

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

我正在開發一個連接 woocommerce 和支付 API 的插件,在那里我需要發送一系列產品詳細信息,例如產品 ID、名稱、描述、數量和個人金額.

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.

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

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

如何獲取這些數據?

謝謝

以下是針對需要它的每個人的答案的更新:

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

推薦答案

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

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);
    }
}

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

希望這有幫助!

這篇關于WooCommerce 在插件付款前獲取訂單產品詳細信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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精品视频在线 | 欧美综合激情 | 在线一区二区三区四区 | 日韩av免费在线播放 | 日日夜夜狠狠 | 日韩女优在线 | 久久久久综合 | 青青草一区二区 | 超碰在线观看免费版 | 亚洲精品aaa | 精品一区二区三区四区 | 国产麻豆xxxvideo实拍 | 欧美日韩综合 | 999久久久 | 国产精品二| www.日韩精品| a毛片大片 | 国产精品亚洲一区 | 天堂av影视 | 天天射天天操天天干 | 91av免费| 最新日韩在线 | 国产精品美女久久久 | 97久久久| 黄色片网站在线观看 | 国产黄色片在线观看 | 欧美性色网 | 欧美激情自拍 | 性爱一级视频 | 亚洲免费看片 | 婷婷一区二区三区 | 国产福利av| 国产欧美一区二区精品忘忧草 | 成人毛片在线 | 日韩999 | 国产精品偷乱一区二区三区 | 午夜精品视频在线观看 | 一区二区小视频 | 亚洲高清在线视频 | 午夜免费福利视频 | www.中文字幕.com |