doublestar2014 2017-11-05 12:01
浏览 48
已采纳

WooCommerce:显示循环内的产品变化

How can I display the product variations for each product within a loop such as the one on the Shop page? Is there any function that I can add to the content-product template that retrieves the list of variations and displays them?

  • 写回答

2条回答 默认 最新

  • douxin0251 2017-11-05 12:37
    关注

    Best way to do this is alter the loop. Something like that will help:

       function filter_wc_query($query_args){
          if(is_archive()){ //here you can use any conditional function to show variations on 
            $query_args[] = ['post_parent'=> '*'];
          }
          return $query_args;
       }
       add_filter('woocommerce_get_query_vars','filter_wc_query');
    

    Or if you want to this on view level: https://gist.github.com/lukecav/2470d9fe6337e13da4faae2f6d5fe15f

    In this solution image you can grab by standard WP function:

    get_post_thumbnail($product->ID,'shop_list');
    

    But remeber that variation link will bring user to parent product and force him to select variation once more.

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

报告相同问题?

悬赏问题

  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题