我有以下几张幻灯片,检查某一物品是否库存,如果是,将物品的地位从公布后改写。 我怎样才能在这个问询中排除一个类别? 谢谢!
add_action( admin_init , woo_moveoutofstocktodraft );
function woo_moveoutofstocktodraft() {
$current_user = wp_get_current_user();
//if loggedin user does not have admin previlage
if (!user_can($current_user, administrator )) {
return;
}
$params = [
posts_per_page => -1,
post_type => product ,
post_status => publish
];
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) :
while ($wc_query->have_posts()) :
$wc_query->the_post();
$product_id = get_the_ID();
$product = wc_get_product($product_id);
//if product is Out of Stock move to draft
if (!$product->is_in_stock()) {
$post = array( ID => $product_id, post_status => draft );
wp_update_post($post);
}
endwhile;
wp_reset_postdata();
endif;
}