2014-10-03 26 views
3

使用WooCommerce REST Client Library,我可以很容易地拉訂單是在加工,像這樣:WooCommerce REST API - 檢索指令屬性(大小/顏色)

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

但結果不包括屬性(顏色,大小等),即使購買的產品設置了與產品變體相關的大小/顏色屬性。這部分工作都很好。客戶可以選擇產品的尺寸和顏色,但該信息不會以get_orders查詢顯示。

這裏是不顯示出來:

<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> 

正如你可以看到,即使客戶已經選擇了「大/黑」的變化,它不會在get_orders數據顯示。

我可以拉可用屬性使用相同的庫產品,但我需要拉客戶選擇的屬性爲順序

+0

我是從Magento的經驗談起,同樣可能適用於woocommerce:您需要獲取訂單的產品,並從該集合/數組中獲得產品的詳細信息,如「weight」和「size」 – tawfekov 2014-10-05 20:26:43

+0

I ** can ** access來自REST API的產品細節;例如,我可以讓它爲特定產品提供可用的「顏色」選項。但是,這並不能告訴我,當訂單下達時顧客選擇了什麼「顏色」。 REST API似乎沒有提供該數據,也沒有提供所選的「大小」或任何其他「可變」數據字段。 – 2014-10-06 04:46:27

回答

5

我討厭回答我的問題,但事實證明,答案很簡單:

WooCommerce REST Client Library對API的V2一直沒有更新,即使WooCommerce鏈接它作爲V2的資源。該解決方案是非常簡單的:

導航到〜/類-WC-API client.php和變線17:

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

的API立即返回正確的數據時,我做了一個get_orders ()查詢。

1

我再次從Magento的背景談起who would like to get that bounty :P 我認爲你必須分別處理每個訂單形成了你,你上面

產生的訂單報價列表這個link

你可以通過訂單的訂單項目

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

那麼,如果你通過他們循環,你可以得到所有的相關數據:

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 
} 
+0

是的,如果你是在Wordpress/WooCommerce框架內做的話,這可能是做到這一點的方式 - 可能是一個插件。但REST API不提供對WC_Order的這種直接訪問,而且它是我嘗試使用的REST API。 – 2014-10-06 04:42:10