没有得到不同的价格,每个图片的价格都相同,但标题的ID却不同

时间:2019-07-15 06:57:33

标签: php jquery twitter-bootstrap-3

<div id="products" class="row list-group">

         <?php $counter = 1; foreach ($photo_products as $value) { 
                $product = new WC_Product( $value->ID ); ?>
    <div class="item  col-xs-4 col-lg-4">
        <div class="thumbnail">
            <img class="myImg" class="group list-group-image" src="<?php echo get_the_post_thumbnail_url($value->ID, array(324, 324)); ?>" alt="" />
            <div class="caption">
                <h4 class="group inner list-group-item-heading">
                   <?php echo esc_attr($product->get_title()); ?></h4>

                <div class="row">
                    <div class="col-xs-12 col-md-6">
                        <p class="lead">
                           <?php echo wc_price($product->get_price()); ?></p>
                    </div>
                    <div class="col-xs-12 col-md-6">
                        <a class="btn btn-success " href="<?php echo esc_attr($current_url).'/?add-to-cart='.esc_attr($value->ID); ?>">
                            <?php esc_html_e('Add to cart', 'woocommerce-photography-plugin'); ?>

                            </a>

                    </div>
                </div>
            </div>
             <div id="myModal" class="modal">
                     <span class="close">&times;</span>
                  <img id="img01" class="modal-content"  src="">
                    <div id="caption"  class="modal-content">
                        <h4 class="group inner list-group-item-heading">
                   <?php echo esc_attr($product->get_title()); ?></h4>
                   <div class="row">
                    <div class="col-xs-12 col-md-6">
                        <p class="lead" >
                           <?php echo wc_price($product->get_price()); ?></p>
                    </div>
                    <div class="col-xs-12 col-md-6">
                        <a class="btn btn-success " href="<?php echo esc_attr($current_url).'/?add-to-cart='.esc_attr($value->ID); ?>">
                            <?php esc_html_e('Add to cart', 'woocommerce-photography-plugin'); ?>

                            </a>

                    </div>


                    </div>
                </div>
           </div>
        </div>

    </div>


        <?php $counter++; } ?>
 </div>

1 个答案:

答案 0 :(得分:1)

代替

$product = new WC_Product( $value->ID );

您可以尝试以下代码:

$product = WC_Product::find()->where('id'=>$value->ID);