WooCommerce get order product detail programatically

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

        }

Search

Recent Blogs

Categories

Archives

Archives

Tags