• Resolved leest801003

    (@leest801003)


    I have some php code which i am trying to use to get a list of product items for an order so that i can automatically print custom packaging slips. Everything works fine, i can get the order number, the order status etc, but it keeps coming up and saying no product items found.

    // Loop through order items and add them to the PDF (Picking List)
    
        $items = $order->get_items();
    
        error_log('Order Items: ' . print_r($items, true)); // Debugging the items
    
        if (empty($items)) {
    
            error_log("No items found in order ID: " . $order_id);
    
        }
    
        foreach ($items as $item_id => $item) {
    
            $product_name = $item->get_name(); // Get the item name (product name)
    
            $item_quantity = $item->get_quantity(); // Get the item quantity
    
            // Add item name and quantity to the PDF (Picking List)
    
            $pdf->Cell(0, 10, "Product name: {$product_name} | Quantity: {$item_quantity}", 0, 1);
    
        }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi
    try this way

    $order = wc_get_order($order_id);
    
    // Check if the order exists
    if (!$order) {
        error_log("Order not found for ID: " . $order_id);
        return;
    }
    
    // Get the order items
    $items = $order->get_items();
    
    // Check if the order has items
    if (empty($items)) {
        error_log("No items found in order ID: " . $order_id);
        return;
    }
    
    // Accessing WooCommerce Order Details
    foreach ($items as $item_id => $item) {
        $product_id      = $item->get_product_id();
        $variation_id    = $item->get_variation_id();
        $product         = $item->get_product(); 
    // Product object gives you access to all product data
        $product_name    = $item->get_name();
        $quantity        = $item->get_quantity();
        $subtotal        = $item->get_subtotal();
        $total           = $item->get_total();
    
        // Use the retrieved details as needed
        // For example, you can add them to the PDF (Picking List)
        $pdf->Cell(0, 10, "Product ID: {$product_id} | Variation ID: {$variation_id} | Product Name: {$product_name} | Quantity: {$quantity} | Subtotal: {$subtotal} | Total: {$total}", 0, 1);
    }
    

    Thanks
    Ahir

    Hi @leest801003

    Thanks for reaching out!

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Product Items not being found’ is closed to new replies.