Php 如何从我的WooCommerce产品标签条款中获取自定义字段?
使用高级自定义字段插件,我在我的WooCommerce产品标签中添加了一个“图像”自定义字段 现在,我使用下面的方法将附加的产品标签术语添加到我的产品中Php 如何从我的WooCommerce产品标签条款中获取自定义字段?,php,wordpress,woocommerce,advanced-custom-fields,taxonomy-terms,Php,Wordpress,Woocommerce,Advanced Custom Fields,Taxonomy Terms,使用高级自定义字段插件,我在我的WooCommerce产品标签中添加了一个“图像”自定义字段 现在,我使用下面的方法将附加的产品标签术语添加到我的产品中 $terms = wp_get_post_terms( $product_id, 'product_tag' ); 但我无法获取我的“图像”自定义字段 如何从我的WooCommerce产品标签条款中获取图像自定义字段?首先在图像字段的ACF设置中,确保您已选择了返回格式中的“图像ID”选项: 您将使用动态$product\u id变量中的以
$terms = wp_get_post_terms( $product_id, 'product_tag' );
但我无法获取我的“图像”自定义字段
如何从我的WooCommerce产品标签条款中获取图像自定义字段?首先在图像字段的ACF设置中,确保您已选择了返回格式中的“图像ID”选项: 您将使用动态
$product\u id
变量中的以下内容来获取并显示WooCommerce产品标签条款的附加图像:
$product_tag_terms = wp_get_post_terms( $product_id, 'product_tag' );
foreach ( $product_tag_terms as $term ) {
$image_id = get_field( 'image', $term );
if ( ! empty($image_id) && is_numeric($image_id) ) {
$image = wp_get_attachment_image( $image_id );
echo $image; // Output
}
}
测试和工作
ACF文件: