1

Есть конструкция для получения информации о заказе, при указании id заказа вручную, все работает. Как получить id заказа не зная его? или получить информацию о заказе без id.

    add_action( 'woocommerce_new_order', 'get_order_details_woo',  1, 1  );



function get_order_details_woo ($id, $order )
{
    $order_id = $order->get_id();
    $order = wc_get_order($order_id);

    $item_data = $order->get_data();



// Iterating through each WC_Order_Item_Product objects
    foreach ($order->get_items() as $item_key => $item_values) {

        ## Using WC_Order_Item methods ##
        // Item ID is directly accessible from the $item_key in the foreach loop or
        $item_id = $item_values->get_id();

        ## Using WC_Order_Item_Product methods ##

        $item_name = $item_values->get_name(); // Name of the product
        ## Access Order Items data properties (in an array of values) ##
        $item_data = $item_values->get_data();

        $product_name = $item_data['name'];
        $product_id = $item_data['product_id'];
        $variation_id = $item_data['variation_id'];
        $quantity = $item_data['quantity'];
        $tax_class = $item_data['tax_class'];
        $line_subtotal = $item_data['subtotal'];
        $line_subtotal_tax = $item_data['subtotal_tax'];
        $line_total = $item_data['total'];
        $line_total_tax = $item_data['total_tax'];


      //  prepare_arr_items($product_name, $quantity, $line_total, $order_id);
}
}

1 ответ 1

0
$firstname = $order->get_billing_first_name();

Вот таким методом всё можно передавать.

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.