반응형
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
반응형
'codememo' 카테고리의 다른 글
| outside/esc 클릭 시 Angularjs 부트스트랩모달 종료 콜 (0) | 2023.02.08 |
|---|---|
| 각도 js에 ng-include 로드 완료 (0) | 2023.02.08 |
| 이동 시 JSON Marshal이 포함된 소문자 JSON 키 이름 (0) | 2023.02.08 |
| PHP 루프:세 항목 구문 주위에 div를 추가합니다. (0) | 2023.02.08 |
| Angular.js 지시어에서 ng는 무엇을 나타냅니까? (0) | 2023.02.08 |