1

How we can get the complete cart details from the order id in woocommerce including the totals and subtotals etc.

3 Answers 3

1

Try this:

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
?>
1
  • Not sure how this could be the accepted answer, as I know $woocommerce->cart->get_cart() will return the cart from the "current" session, but the question is about how to get the details (including totals and items) for exist (old) order!
    – Walid Ajaj
    Dec 20, 2021 at 12:07
1

You can get order's cart details from the order object.

if you only have the id, you can get $order object like this:

// Get $order object from order ID
  
$order = wc_get_order( $order_id );

to get order's details:

if ( $order ) {

    // Get Order Totals $0.00
    $order->get_formatted_order_total();
    $order->get_cart_tax();
    $order->get_currency();
    $order->get_discount_tax();
    $order->get_discount_to_display();
    $order->get_discount_total();
    // etc.
    // etc.

    // Get and Loop Over Order Items
    foreach ( $order->get_items() as $item_id => $item ) {
       $product_id = $item->get_product_id();
       $variation_id = $item->get_variation_id();
       // etc.
       // etc.
    }
}

You can refer to this link for more details: https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/

0

Another variant:

<?php

WC()->cart->get_cart();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.