2014-03-19 62 views
2

我用下面的函數調用來獲取產品的變化,如何從woocommerce中的變體ID中檢索變體名稱?

$available_variations = $product->get_available_variations(); 

而在返回$ available_variations我所有的變化。

我得到了variation_id,而且我不知道該屬性的名稱,在本例中屬於原產國,那麼如何檢索屬性值,即香港和新加坡在這種情況下?

下面是高於$ available_variations的轉儲,

[18-Mar-2014 17:04:20 UTC] Array 
(
[variation_id] => 2968 
[attributes] => Array 
    (
     [attribute_pa_country-of-origin] => hong-kong 
    ) 

[image_src] => 
[image_link] => 
[image_title] => 
[image_alt] => 
[price_html] => <span class="price"><span class="amount">SGD$15</span></span> 
[availability_html] => 
[sku] => 
[weight] => kg 
[dimensions] => 
[min_qty] => 1 
[max_qty] => 0 
[backorders_allowed] => 
[is_in_stock] => 1 
[is_downloadable] => 
[is_virtual] => 
[is_sold_individually] => no 
) 

[18-Mar-2014 17:04:20 UTC] Array 
(
[variation_id] => 2969 
[attributes] => Array 
    (
     [attribute_pa_country-of-origin] => singapore 
    ) 

[image_src] => 
[image_link] => 
[image_title] => 
[image_alt] => 
[price_html] => <span class="price"><span class="amount">SGD$12</span></span> 
[availability_html] => 
[sku] => 
[weight] => kg 
[dimensions] => 
[min_qty] => 1 
[max_qty] => 0 
[backorders_allowed] => 
[is_in_stock] => 1 
[is_downloadable] => 
[is_virtual] => 
[is_sold_individually] => no 
) 

回答

-5

您可以通過使用循環或僅僅作爲

echo $available_variations[0]['variation_id']; 
echo $available_variations[1]['variation_id']; 
echo $available_variations[2]['variation_id']; 
echo $available_variations[3]['variation_id']; 
+0

這不是海報問的問題,他希望從變體ID中獲取變體的名稱 – Roy

0

我知道這是舊的,但只是櫃面有人需要這樣的獲得ID未來,並遇到這個帖子,正確的方法是。

echo $available_variations[0][attributes][attribute_pa_country-of-origin]; 
echo $available_variations[1][attributes][attribute_pa_country-of-origin];