woocommerce製品のバリエーションから属性を取得する必要があります。バリエーションにslugの代わりに属性名を取得するには?
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
このコードは、名前の代わりに属性スラッグを与えています。属性名はどのように取得できますか?
ありがとうございました!
woocommerce製品のバリエーションから属性を取得する必要があります。バリエーションにslugの代わりに属性名を取得するには?
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
このコードは、名前の代わりに属性スラッグを与えています。属性名はどのように取得できますか?
ありがとうございました!
タクソノミーのスラッグです... attribute_
のないattribute_pa_color
のWooCommerceでは分類法です。
だから、このようなものを試してみると、スラッグの言葉を得ることができます。それに名前をつけろ。
$taxonomy = 'pa_color';
$meta = get_post_meta($value['variation_id'], 'attribute_'.$taxonomy, true);
$term = get_term_by('slug', $meta, $taxonomy);
echo $term->name;
次のコードを試すことができます。
$terms = get_the_terms($value['variation_id'] , 'attribute_pa_color');
foreach ($terms as $term) {
echo $term->name;
}
それが役に立ったかどうかを教えてください。追加情報については、thisリンクに記載されている説明を参照してください。
うわー、うーん!どうもありがとうございます! – Pupik