【发布时间】:2015-03-24 08:10:25
【问题描述】:
使用高级自定义字段插件,我试图在 WooCommerce 中的单个产品页面上呈现图像。
我从一个做同样事情的人那里找到了这个 sn-p 代码,但它正在渲染一个文本字段。我将如何更改它以呈现图像?
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_top_category_desc', 1 );
function woocommerce_template_top_category_desc (){
$terms = get_the_terms( $post->ID, 'wc-attibute-class' );
if ( !empty($terms)) {
$term = array_pop($terms);
$text= get_field('txt-field', $term);
if (!empty($text)) {
echo $text;
}
}
}
到目前为止,我有这个,但它不起作用。 add 操作是正确的,因为我将它用于其他用途,但从 $terms 开始是我迷路的地方,显然是不对的。
add_action( 'woocommerce_product_thumbnails' , 'add_below_featured_image', 9 );
function add_below_featured_image() {
$terms = get_the_terms( $post->ID, '496' );
if ( !empty($terms)) {
$term = array_pop($terms);
$image = get_field('banner_feedback', $term);
if (!empty($image)) {
echo $image;
}
}
}
【问题讨论】:
标签: wordpress woocommerce field custom-fields advanced-custom-fields