WooCommerce Получить заказ Сведения о продукте Перед оплатой в плагине

Мне нужно отобразить детали заказа из корзины до оплаты в плагине.

Я работаю над одним плагином, что подключает woocommerce и API оплаты, и там мне нужно отправить массив деталей продукта, таких как идентификатор продукта, имя, описание, количество и индивидуальную сумму.

Моя проблема в том, что я не могу найти правильный крюк, чтобы получить все данные правильно.

Как я могу получить эти данные?

благодаря

ОБНОВИТЬ

Вот обновление, основанное на anwers для всех, кто в этом нуждается:

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

    Я думаю, вы ищете woocommerce_checkout_process hook. WC_Checkout::process_checkout() – Обработайте проверку после нажатия кнопки подтверждения заказа.

    Вот код:

     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-файлов.

    Надеюсь это поможет!

    Вот все данные о товарах, которые вы можете получить с объектом тележки:

     foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){ $product_id = $cart_item['product_id']; // Product ID $product_obj = wc_get_product($product_id); // Product Object $product_qty = $cart_item['quantity']; // Product quantity $product_price = $cart_item['data']->price; // Product price $product_total_stock = $cart_item['data']->total_stock; // Product stock $product_type = $cart_item['data']->product_type; // Product type $product_name = $cart_item['data']->post->post_title; // Product Title (Name) $product_slug = $cart_item['data']->post->post_name; // Product Slug $product_description = $cart_item['data']->post->post_content; // Product description $product_excerpt = $cart_item['data']->post->post_excerpt; // Product short description $product_post_type = $cart_item['data']->post->post_type; // Product post type $cart_line_total = $cart_item['line_total']; // Cart item line total $cart_line_tax = $cart_item['line_tax']; // Cart item line tax total $cart_line_subtotal = $cart_item['line_subtotal']; // Cart item line subtotal $cart_line_subtotal_tax = $cart_item['line_subtotal_tax']; // Cart item line tax subtotal // variable products $variation_id = $cart_item['variation_id']; // Product Variation ID if($variation_id != 0){ $product_variation_obj = wc_get_product($variation_id); // Product variation Object $variation_array = $cart_item['variation']; // variation attributes + values } }