[英]Show product-category thumbnails in loop which have n price of products in woocommerce
我想循環顯示具有n個產品價格的類別縮略圖。 在這里,n價格將從管理面板中填滿一定數量的商品,並且該產品類別縮略圖將顯示在該商品數量等於或大於該商品數量的頁面上。 因此,如果可以的話,請幫助我寫查詢或任何其他解決方案。
我嘗試了這段代碼並獲得成功。
//backend option for price
$value= get_option('price');
// the query
$args = array ('meta_query' => array(
array( 'key' => '_price',
'value' => $value,
'compare' => '>=',
'type' => 'NUMERIC',
),
),
'post_type' => 'product',
);
// The Query
$query = new WP_Query( $args ); ?>
<?php if ( $query->have_posts() ) : ?>
<!-- the loop -->
<?php $stack = array();?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php $a = $product->get_categories(); ?>
<?php if (!in_array($a, $stack)) : ?>
<li class="product-category">
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_id = $term->term_id;
$category_slug = $term->slug;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
echo '<img class="absolute category-image" src="'.$image.'">';
}
echo '<a href="' . get_term_link( $category_slug, 'product_cat' ) . '?min_price='.$value.'&max_price=1000500' . '">' . $category_name . '</a>';
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.