WooCommerce REST API - Get Order Attributes (Size / Color)

Using the WooCommerce REST Client Library I can easily pull out orders that are being processed, for example:

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

      

But the results DO NOT include attributes (color, size, etc.), although the purchased product was customized with the Size / Color attributes that correlate with product variations. Everything works fine in this part. Customer can choose the size and color of the product, but this information is NOT displayed with the request get_orders

.

Here's what it shows:

<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, although the client has selected the Large / Black option for the options, it does not appear in the data get_orders

.

I can pull the available attributes for a product using the same library, but I need to pull the user selected attributes for...

+3


source to share


2 answers


I hate to answer my own question, but it turns out the answer is pretty simple:

The WooCommerce REST client client library has not been updated for the V2 API, although WooCommerce bundles it as a V2 resource. The solution is very simple:

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



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

The API returned the correct data immediately when I made a get_orders () request.

+5


source


again i say from magento background who would like to get that bounty :P

i think you should process each order separately from your list of orders you created above.

referring to the link

you can get the order items



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

      

then if you go 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 
}

      

+1


source







All Articles