我正在使用WooCommerce变体样例和照片插件,该插件允许我在产品属性中添加缩略图。
我需要列出一个模板上的所有属性,我也想得到并显示缩略图。
$terms = get_terms( array(
\'taxonomy\' => \'pa_texture\',
\'hide_empty\' => false,
) );
foreach ( $terms as $term ) {
print_r($term);
}
缩略图功能不是WooCommerce中的默认功能,因此当我打印r$term时,没有缩略图URL:
WP_Term Object
(
[term_id] => 54
[name] => Guilin
[slug] => guilin
[term_group] => 0
[term_taxonomy_id] => 54
[taxonomy] => pa_texture
[description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla imperdiet facilisis convallis.
[parent] => 0
[count] => 2
[filter] => raw
[meta_value] => 0
)
如何获取属性的缩略图?
最合适的回答,由SO网友:Jeff 整理而成
我通过使用get_woocommerce_term_meta
$terms = get_terms( array(
\'taxonomy\' => \'pa_texture\',
\'hide_empty\' => false,
));
foreach ( $terms as $term ) :
$thumbnail_id = get_woocommerce_term_meta( $term->term_id, \'pa_texture_swatches_id_photo\', true );
$textureImg = wp_get_attachment_image_src( $thumbnail_id, \'full\' ); ?>
<img src="<?php echo $textureImg[0]; ?>">
endforeach;