gpt4 book ai didi

woocommerce - 如何从 woocommerce 中的变体 ID 检索变体名称?

转载 作者:行者123 更新时间:2023-12-05 07:59:08 25 4
gpt4 key购买 nike

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

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

最佳答案

我知道这是旧的,但以防万一将来有人需要它并看到这篇文章,正确的方法是。

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

关于woocommerce - 如何从 woocommerce 中的变体 ID 检索变体名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22509744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com