Wordpress WooCommerce:有没有办法查看不属于某个类别的所有产品?

Wordpress WooCommerce: is there a way to view all products that are not in a category?

有些产品我只需要在美国展示。我有一个标有“美国”的类别包含它们,但是我需要将所有不属于该类别的产品放入一个名为“世界其他地区”的新产品中

有没有简单的方法来做到这一点?

我正在尝试找到一种方法来在美国展示 ~200 种产品(我的 ~400 种产品商店中的),而无需进入每一种产品并进行标记或查找 ID。

我的计划是:

  1. 查找不属于美国类别的所有产品
  2. 将它们添加到新的“世界其他地区”类别
  3. 对于美国的位置隐藏类别“世界其他地区”
  4. 否则显示两个类别

如果有更好的解决方案,我会洗耳恭听!

人们只是把-1 没有任何反馈也没有理由让我生气......

A​​nw,只要您的产品属于其各自类别,以下内容就可以解决问题。我已经提供了很多选项,只是选择了最适合您的选项您也可以查看此文档以了解有关 wordpress 查询的一些信息 https://developer.wordpress.org/reference/classes/wp_query/

这只是一个通用循环,您可以在其中指定所需的 post 类型(此处产品使用的是 woocom)和所需的类别。

如果它是自定义分类法,而不仅仅是插入默认产品类别中的术语,那么您可能需要进行更多调整,但不会太多。希望对您有所帮助。

<!-- Start loop here -->
<?php
/* For Choice 3 ONLY add the following:
Warning: You need to use the category NAME
$cat_id = get_cat_ID ( 'USA' ); */
$query = new wp_query( array(
'post_type'         => 'product',

/* Choice 1 - Display product with category "USA" AND ALSO product with category "Rest of world"
Using the separator ",".
Warning: You need to use the category SLUG
'category_name'     => 'usa,rest-of-the-world', */

/* Choice 2 - Display product with category "USA" AND "Rest of world"
Using the separator "+".
Warning: You need to use the category SLUG
'category_name'     => 'usa+rest-of-the-world', */

/* Choice 3 - Display all products without category "USA"
You could also use the category id
'cat'     => '-' . $cat_id, */

'post_status'       => 'publish',
/* To display all products replace the post_per_page value by '-1'
'posts_per_page'    => '-1', */
'posts_per_page'    => '3',
) ); ?>
<?php if ( $query->have_posts() ): while ( $query->have_posts() ): $query->the_post(); ?>
<!-- Start template here -->
<div><a aria-label="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<!-- End template here -->
<?php endwhile; endif; ?>
<!-- End loop here -->