[英]Can't display custom product attribute data on Single Product page with ACF and WooCommerce
我創建了一個產品屬性,並在該產品屬性上添加了帶有 ACF 的自定義字段,但是我無法在單個產品頁面上顯示該自定義字段。
<?php
function brandLogo(){
$terms = get_terms( 'brand' , array( 'hide_empty' => false ) );
foreach( $terms as $term ) :
$thumbnail_image = get_field( 'brand_logo', 'brand' . $term->term_id );
?><img src="<?php echo $thumbnail_image ?>"> <?php
endforeach;
}
add_shortcode('brandLogo', 'brandLogo');
//$terms = get_the_terms($product->id, 'brand');
//$brandLogo = get_field('brand_logo', $term->taxonomy . '_' . $term->term_id );
?>
標簽顯示在前端,但返回 null。 我的屬性稱為“品牌”,我的自定義屬性是“brand_logo”。 我正在努力理解這方面的任何文檔。
任何人都可以建議更改我的代碼以在我的單個產品頁面上的產品屬性上顯示自定義字段嗎?
我更改了代碼並了解到對 WooCommerce 產品屬性使用“pa_attributename”很重要。 這是工作代碼:
<?php
function brandLogo(){
global $product;
$terms = get_the_terms($post->ID , 'pa_brand');
if($terms){
foreach ($terms as $term){
?><img src="<?php the_field('brand_logo', 'pa_brand' . '_' . $term->term_id) ?>"/><?php
}
}
}
add_shortcode('brandLogo', 'brandLogo');
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.