WooCommerce:在循环内显示产品变体 [英] WooCommerce: Display product variations inside of loop

查看:34
本文介绍了WooCommerce:在循环内显示产品变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在循环(例如商店"页面上的循环)中显示每个产品的产品变体?是否有任何函数可以添加到 content-product 模板中以检索变体列表并显示它们?

解决方案

最好的方法是改变循环.这样的事情会有所帮助:

 函数 filter_wc_query($query_args){if(is_archive()){//在这里你可以使用任何条件函数来显示$query_args[] = ['post_parent'=>'*'];}返回 $query_args;}add_filter('woocommerce_get_query_vars','filter_wc_query');

或者,如果您想在视图级别执行此操作:https://gist.github.com/lukecav/2470d9fe6337e13da4faae2f6d5>fe15p

在此解决方案图像中,您可以通过标准 WP 功能抓取:

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

但请记住,变体链接会将用户带到父产品并迫使他再次选择变体.

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?

解决方案

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.

这篇关于WooCommerce:在循环内显示产品变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆