Woocommerce - 仅在循环中显示分组的产品父级 [英] Woocommerce - Only show grouped products parent in the loop

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

问题描述

我正在开一家书店.我有一堆分组产品.我的痛苦是,woocommerce 默认列出了这两种类型.我只需要列出组的父级没有子级.

I'm building a store for books. I have a bunch of grouped products. My pain is, that woocommerce lists both type by default. I only need the parent of the group to be listed without childrens.

是否有任何钩子或解决方法?

Is there any hook or workaround for this?

谢谢.

推荐答案

尝试以下操作:

add_action( 'woocommerce_product_query', 'so_27975262_product_query' );

function so_27975262_product_query( $q ){
    $q->set( 'post_parent', 0 );
}

这个想法是我们正在修改查询,以便它只显示顶级项目......因此(理论上)没有分配给组的任何内容,然后组产品的 ID 为post_parent.

The idea is that we're modifying the query such that it will only show top-level items.... thus (in theory) nothing that has been assigned to a group, which would then have the group product's ID as the post_parent.

这篇关于Woocommerce - 仅在循环中显示分组的产品父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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