У меня есть следующий код в моей дочерней теме function.php, и я получаю все идентификаторы терминов.Но функция get_woocommerce_term_meta не возвращает никаких значений.Я использую последнюю версию Woocommerce и Wordpress.Кроме того, тот же код работает нормально в другом файле шаблона без каких-либо проблем.Я не уверен, что мне здесь не хватает.
add_action('init', 'remove_home_page_sections',0);
add_action('homepage', 'custom_storefront_product_categories',20);
function remove_home_page_sections(){
remove_action( 'homepage','storefront_homepage_content',10);
remove_action( 'homepage','storefront_product_categories',20);
}
function custom_storefront_product_categories(){
$cat_args = array(
'taxonomy' => 'product_cat',
'hide_empty' => true,
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',);
$terms = get_terms($cat_args);
foreach ( $terms as $term ) {
$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
// get the medium-sized image url
echo $image = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
echo "-->".$term->term_id."--[".$thumbnail_id."]";
}
}