【发布时间】:2022-10-07 19:06:20
【问题描述】:
我正在使用自定义查询来获取产品类别,并且我也想要它们的库存产品数量,我设法获得了数量,但它也显示了我不想要的缺货数量:(
知道如何从库存中排除缺货产品数量吗?
我做了一些研究,发现我们可以排除缺货产品https://prnt.sc/8wpCstT_-jrf 但它也会从商店页面中删除产品,我只想将它们从计数中删除,这是我的代码:
提前致谢 :)
function newcats_shortcode() {
$taxonomy = \'product_cat\';
$orderby = \'name\';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 1; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = \'\';
$empty = 0;
$args = array(
\'taxonomy\' => $taxonomy,
\'orderby\' => $orderby,
\'show_count\' => $show_count,
\'pad_counts\' => $pad_counts,
\'hierarchical\' => $hierarchical,
\'title_li\' => $title,
\'hide_empty\' => $empty
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo \'<br /><a href=\"\'. get_term_link($cat->slug, \'product_cat\') .\">\'. $cat->name .\' \'. $cat->count .\'</a>\';
// echo \"<pre>\", var_dump($cat) ,\"</pre>\";
}
}
}
add_shortcode( \'newcats\', \'newcats_shortcode\' );
标签: php wordpress woocommerce