2017-05-02 8 views
-1

グループ化された製品を最高価格にしようとしているので、カスタムテンプレートページで最高の価格しか表示できません。WP_Queryを使用して製品のリストを取得しています。ここで グループ化された製品の最高値woocommerceを取得

は抜粋です:

    $series_term = $_GET['series']; 
        $args=array(
         'series' => $term_name->slug, 
         'post_type' => 'product', 
         'posts_per_page' => 8, 
         'filter' =>$valuecol, 
         'tax_query' => array(
          array(
           'taxonomy' => 'product_cat', 
           'field' => 'slug', 
           'terms' => array('hidden'), // Don't display products in the knives category on the shop page 
           'operator' => 'NOT IN' 
          ) 
         ) 
        ); 

       // $do_not_duplicate[] = $post->ID; 
       $my_query = null; 
       $my_query = new WP_Query($args); 
       /* Start the Loop */ 
       while ($my_query->have_posts()) : $my_query->the_post(); 
       $feat_prod_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'post-thumb-single');         
       $feat_product_img = wp_get_attachment_url(get_post_thumbnail_id($my_query->post->ID)); 
          ?> 
        <div class="col-md-3 col-sm-4 col-xs-6"> 
         <div class="product-detail"> 
          <div class="product-thmbnial"> 
           <a href="<?php the_permalink(); ?>"> 
            <img src="<?php $src=$feat_product_img; echo image_product_resize_crop($src, $w=440, $h=275, $dest = null, $override = false, $createNewIfExists = false); ?>" alt="<?php the_title(); ?>"/> 
           </a> 
          </div> 
          <div class="info"><p><a href="<?php the_permalink();?>"><?php the_title(); ?></a><br/> 
           <span> 
           <?php $wp_product = new WC_Product(get_the_ID()); 
           echo get_woocommerce_currency_symbol(); ?></sup><?php 
          echo $wp_product->get_price();?></span></p></div> 
         </div> 
        </div> 
       <?php endwhile; ?> 

私はグループ化された製品の最高価格は$ wp_product-> get_price()の代わりに表示したいです。

子供の製品を取得しようとしましたが、配列は空です。

foreach ($wp_product->get_children() as $child_id) { 
    $child_prices[] = get_post_meta($child_id, '_price', true); 
} 

どのように私は最高の価格を得ることができます誰も私にお勧めできます。 ありがとうございます。

答えて

0

私は解決策を見つけました。以前は同じソリューションを試しましたが、その時は機能しませんでした。ここで

は修正です:

$series_term = $_GET['series']; 
        $args=array(
         'series' => $term_name->slug, 
         'post_type' => 'product', 
         'posts_per_page' => 8, 
         'filter' =>$valuecol, 
         'tax_query' => array(
          array(
           'taxonomy' => 'product_cat', 
           'field' => 'slug', 
           'terms' => array('hidden'), // Don't display products in the knives category on the shop page 
           'operator' => 'NOT IN' 
          ) 
         ) 
        ); 

       // $do_not_duplicate[] = $post->ID; 
       $my_query = null; 
       $my_query = new WP_Query($args); 
       /* Start the Loop */ 
       while ($my_query->have_posts()) : $my_query->the_post(); 
       $feat_prod_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'post-thumb-single');         
       $feat_product_img = wp_get_attachment_url(get_post_thumbnail_id($my_query->post->ID)); 
          ?> 
        <div class="col-md-3 col-sm-4 col-xs-6"> 
         <div class="product-detail"> 
          <div class="product-thmbnial"> 
           <a href="<?php the_permalink(); ?>"> 
            <img src="<?php $src=$feat_product_img; echo image_product_resize_crop($src, $w=440, $h=275, $dest = null, $override = false, $createNewIfExists = false); ?>" alt="<?php the_title(); ?>"/> 
           </a> 
          </div> 
          <div class="info"><p><a href="<?php the_permalink();?>"><?php the_title(); ?></a><br/> 
           <span> 
           <?php $wp_product = new WC_Product(get_the_ID()); 
           $child_prices = array(); 
           foreach ($product->get_children() as $child_id) { 
            $child_prices[] = get_post_meta($child_id, '_price', true); 
           } 
           $child_prices = array_unique($child_prices); 
           if (! empty($child_prices)) { 
            $min_price = min($child_prices); 
            $max_price = max($child_prices); 
           } else { 
            $min_price = ''; 
            $max_price = ''; 
           } 
           if($min_price == $max_price && !empty($min_price)) 
           { 
            echo get_woocommerce_currency_symbol(); ?></sup><?php 
            echo $min_price; 
           } 
           elseif(!empty($max_price)) 
           { 
            echo get_woocommerce_currency_symbol(); ?></sup><?php 
            echo $max_price; 
           } 
           else 
           { 
            echo get_woocommerce_currency_symbol(); ?></sup><?php 
            echo $wp_product->get_price(); 
           } 
          ?></span></p></div> 
         </div> 
        </div> 
       <?php endwhile; ?> 
関連する問題