반응형
WooCommerce - 속성이 존재하는지 확인한 후 변수 속성 값을 지정합니다.
slug 'short-title'로 woocommerce 제품의 새로운 속성을 만들었습니다.숍 페이지의 제목을 쇼트 타이틀로 덮어쓰고 싶다는 생각입니다.다음과 같은 루프가 설정되어 있습니다.
if (get_post_meta($product->id, 'short-code', true)) {
$product_name = (get_post_meta($product->id, 'short-code', true));
} else {
$product_name = get_the_title();
}
echo '<div class="product-below"><h4 class="product-name">'.$product_name.'</h4>';
그러나 제품의 짧은 제목 필드에 값을 입력할 때 제목이 덮어쓰지는 않습니다.get_post_meta와는 다른 기능이 필요할 것 같습니다.
다음 작업을 수행할 수 있습니다.
global $product;
$product_name = $product->get_attribute( 'short-code' );
대신
$product_name = get_post_meta($product->id, 'short-code', true)
그리고 만약 당신에게 효과가 없다면 추가된 속성에 대한 slug도 한번 확인해 주세요.short-code
또는short_code
언급URL : https://stackoverflow.com/questions/28955642/woocommerce-check-if-attribute-exists-and-then-give-variable-attribute-value
반응형
'it-source' 카테고리의 다른 글
Wordpress 사이트를 해킹한 후 캐시 제거 (0) | 2023.02.08 |
---|---|
콘텐츠 로드 후 호출할 AngularJs 이벤트 (0) | 2023.02.08 |
Jackson은 'is'를 제거하여 기본 부울 필드의 이름을 바꿉니다. (0) | 2023.02.08 |
한 번에 모든 MySQL 데이터베이스 내보내기 및 가져오기 (0) | 2023.02.02 |
VueJ별 입력값 설정 및 가치내용 혼합 (0) | 2023.02.02 |