在wooCommerce中的[最近_products]短码中排除类别

发布于 2025-02-14 01:43:38 字数 685 浏览 1 评论 0原文

我们有一个在WooCommerce上运行的POS系统,我们用于instore购买。这意味着我们有一个不在网上销售的项目类别。我有一个插件,可成功地从前端隐藏这些类别和相关的产品,但是由于某种原因,当我们使用[最近的_products]短代码时,这不会影响该项目显示。

我试图屠杀短代码以隐藏此特定类别,但是这些项目仍然显示:

[recent_products per_page="4" order="desc" cat_operator="NOT IN" category="instore"]

使用最近的产品的短码,这甚至可以使用吗?是我可能缺少某些东西,还是有其他方式可以显示新产品并排除类别“ instore” - instore 是类别slug,顺便说一句,完整类别名称仅为 instore instore

“类别slug”

这已经困扰着我一段时间了。

任何建议都将是最欢迎的。

此致 唐娜

We have a POS system running on woocommerce which we use for instore purchases. This means we have a category for items that we do not sell online. I have a plugin which succesfully hides these categories and associated products from the front end but this does not affect the items display when we use the [recent_products] shortcode for some reason.

I've attempted to butcher the shortcode to hide this specific category but the items still show:

[recent_products per_page="4" order="desc" cat_operator="NOT IN" category="instore"]

Is this even possible using the recent product's shortcode? Am I maybe missing something or is there another way I can display new products and exclude the category 'instore' - instore is the category slug, by the way, the full category name is Instore only

Category Slug

This has been troubling me for a while now.

Any suggestions will be most welcome.

Best Regards
Donna

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

四叶草在未来唯美盛开 2025-02-21 01:43:38

现在您想将其隐藏在短代码中,为什么不尝试此Quy:

function dont_show_instore_products( $args, $atts ) {
        $args['tax_query'][] = [
                'taxonomy' => 'product_cat',
                'field'    => 'slug',
                'terms'    => ['instore'],
                'operator' => 'NOT IN'
            ];
    return $args;
}
add_filter( 'woocommerce_shortcode_products_query', 'dont_show_instore_products', 10, 2 );

只需将其添加到您的主题的function.php之前,请在结束?>或如果functions.php没有?>只需在最后一行之后添加它,然后让我们看看它是否可以做什么。

Now that you want to hide it from shortcodes, why dont we give this quy a try:

function dont_show_instore_products( $args, $atts ) {
        $args['tax_query'][] = [
                'taxonomy' => 'product_cat',
                'field'    => 'slug',
                'terms'    => ['instore'],
                'operator' => 'NOT IN'
            ];
    return $args;
}
add_filter( 'woocommerce_shortcode_products_query', 'dont_show_instore_products', 10, 2 );

just add this to your theme's functions.php right before the ending ?> or if the functions.php doesnt have ?> just add it after the last line and lets see if it does what it should do.

染墨丶若流云 2025-02-21 01:43:38

仅使用最近的_products短代码就不可能...需要在woocommerce_shortcode_products_querys_query带有一些PHP代码的过滤中挂钩。尽管我认为您可以使用products这样的快捷代码来实现自己想要的东西:

[products limit="4" orderby="id" order="DESC" visibility="visible" cat_operator="NOT IN" category="instore"]

更多示例在这里: https://woocommerce.com/document/woocommerce-shortcodes/#scenario-4-newest-products

It's not possible with the recent_products shortcode alone... would need hook into the woocommerce_shortcode_products_query filter with some PHP code. Though I think you can achieve what you want with the products shortcode like this:

[products limit="4" orderby="id" order="DESC" visibility="visible" cat_operator="NOT IN" category="instore"]

More examples here: https://woocommerce.com/document/woocommerce-shortcodes/#scenario-4-newest-products

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文