dongyumiao5210 2018-09-12 08:21
浏览 75
已采纳

在Woocommerce 3中获取并显示可变的产品价格范围

I am very new to wordpress and woocommerce. I am modifying the twenty seventeen theme's search result page to look like a table. Most of the products are variable products.I am using the code as below to show the results in a table

    <table class="search-res" style="table-layout: auto; width: 100%;">
            <tr><td>
            <?php
            if ( has_post_thumbnail()) 
                the_post_thumbnail('excerpt-thumb');        
                ?></td>
                <td>
                    <?php 
                    the_title( sprintf( '<th class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ) );
                    echo"</a></th>";
                    ?>
                </td>
                <td style="font-style:italic;font-size:small;"><?php the_excerpt(); ?></td>
            <th><?php 
                global $post;
   $product = new WC_Product($post->ID ); 
  echo wc_price($product->get_price_including_tax(1,$product->get_price()));
?></th>
            </tr>

        </table>

The problem that I am facing is here the minimum price of the product is gettiong displayed. Instead I want the price range to show up. Also how can I get rating and category attributes of the product to show up in the table?

  • 写回答

2条回答 默认 最新

  • douhui3330 2018-09-12 18:47
    关注

    You just need to use the WC_Product_Variable get_price_html() method that will do it for you:

    <?php
    global $post;
    
    // Get the WC_Product_Variable instance Object
    $product = wc_get_product( $post->ID ); // Works for any product type
    
    // Displaying the formatted "Min" - "Max" price range
    echo $product->get_price_html();
    ?>
    

    Tested and works

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用