codememo

Woocommerce 3에서 제품 속성 레이블 이름을 가져옵니다.

tipmemo 2023. 2. 8. 17:58
반응형

Woocommerce 3에서 제품 속성 레이블 이름을 가져옵니다.

저는 Woocommerce에서 제품에 많은 제품 속성을 사용하고 있으며, 제품 페이지에 단축코드로 표시될 수 있는 표의 모든 변형을 루프하고 있습니다.

이 테이블의 경우 테이블 헤드에 있는 모든 제품 속성이 필요하며(이는 여러 변형을 반복하기 전) 속성을 다음과 같이 가져옵니다.

$attributes = $product->get_variation_attributes();
foreach ($attributes as $key => $value) {
    echo '<td>'.&key.'</td>';
}

이건 별로 우아하지 않죠?

이것 또한 유효합니다.

$attributes = $product->get_attributes();
foreach ($attributes as $attribute) {
    echo '<td>'$attribute['name']'</td>';
}

두 경우 모두 제품 속성의 장점을 파악합니다.각 이름마다 폴리랑 번역이 있기 때문에 라벨명을 대신 받아야 합니다(용어도 있습니다).

택사노미 슬러그가 아닌 제품 속성 라벨명은 어떻게 얻을 수 있나요?

전용 Woocommerce 기능을 사용합니다.

foreach ($product->get_variation_attributes() as $taxonomy => $term_names ) {
    // Get the attribute label
    $attribute_label_name = wc_attribute_label($taxonomy);

    // Display attribute labe name
    echo '<td>'.$attribute_label_name.'</td>';
}

또는:

foreach ($product->get_attributes() as $taxonomy => $attribute_obj ) {
    // Get the attribute label
    $attribute_label_name = wc_attribute_label($taxonomy);

    // Display attribute labe name
    echo '<td>'.$attribute_label_name.'</td>';
}

언급URL : https://stackoverflow.com/questions/53079907/get-the-product-attribute-label-name-in-woocommerce-3

반응형