WooCommerce get order product detail programatically

Today we talk about how to get WooCommerce order product or item detail programmatically. Sometimes you need to get order product or item information regarding some tweak or change the quantity or any other kind of customization. So let start with our example.

        $orderId = 10;
        $orderDetail = new WC_Order( $order_id );
        $orderItems = $orderDetail->get_items();
        foreach ( $orderItems as $orderItem ) {
            $product      = $orderItem->get_product(); // get the product object
            $productId   = $orderItem->get_product_id(); // product id
            $variationId = $orderItem->get_variation_id(); // variation id
            $itemType    = $orderItem->get_type(); // product type
            $itemName    = $orderItem->get_name(); //  product name
            $quantity     = $orderItem->get_quantity();  // quantity
            $taxClass    = $orderItem->get_tax_class(); // get item class
            $subtotal     = $orderItem->get_subtotal(); // subtotal
            $total        = $orderItem->get_total(); // get total

        }

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!