如何从woocommerce中的Variation id中检索变体名称?

时间:2014-03-19 14:55:10

标签: woocommerce product variation

我使用以下函数调用来获取产品变体,

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

2 个答案:

答案 0 :(得分:0)

我知道这已经过时了但只是因为有人在将来需要这个,并且遇到这个帖子,正确的方法是。

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

答案 1 :(得分:-5)

您可以使用循环或仅作为

来获取ID
echo $available_variations[0]['variation_id'];
echo $available_variations[1]['variation_id'];
echo $available_variations[2]['variation_id'];
echo $available_variations[3]['variation_id'];