WooCommerce REST API – Retrieve Order Attributes (Size / Color)

Using the WooCommerce REST Client Library, I can easily pull orders that are in processing, like so:

$response = $wc_api->get_orders( array( 'status' => 'processing' ) );

But the results do NOT include Attributes (color, size, etc.) even though the purchased product was setup with Size/Color attributes that correlate with product variations. That part all works just fine. The customer can select the size and color of a product, but that information does NOT show up with a get_orders query.

Read More

Here’s what does show up:

<line_items>
     <XML_Serializer_Tag>
         <id>18</id>
         <subtotal>19.99</subtotal>
         <total>19.99</total>
         <total_tax>0.00</total_tax>
         <price>19.99</price>
         <quantity>1</quantity>
         <tax_class />
         <name>Cool T-Shirt You Just Bought!</name>
         <product_id>351</product_id>
         <sku>194953</sku>
     </XML_Serializer_Tag>
 </line_items>

As you can see, even though the customer has selected “Large / Black” for the variations, it does not show up in the get_orders data.

I can pull the available attributes for the product using the same library, but I need to pull the customer-selected attributes for the order.

Related posts

Leave a Reply

2 comments

  1. I hate answering my own question, but it turns out the answer is quite simple:

    The WooCommerce REST Client Library has not been updated for V2 of the API, even though WooCommerce links it as a V2 resource. The solution is extremely simple:

    Navigate to ~/class-wc-api-client.php and change line 17 to:

    const API_ENDPOINT = 'wc-api/v2/';

    The API immediately returned the correct data when I did a get_orders() query.

  2. again I am talking from magento background who would like to get that bounty :P
    I think you must process each order separately form your list of orders you generated above

    quoting this link

    you can get the order items of an order by

    $order = new WC_Order( $order_id );
    $items = $order->get_items();
    

    then if you loop through them, you can get all the relevant data:

    foreach ( $items as $item ) {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        //// you had the product id now you can load the product and get all information  you might need 
    }