admin管理员组

文章数量:1289345

Is there a way to add "new" tag for products, for products that have less than 14 days? I searched all over the internet, but I didn't find a solution. Please help me to do that with php, I will really appreciate. Thanks in advance! I have this code, but it doesn't work

function add_tags() {
$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1
    );
    
$loop = new WP_Query( $args );
if ( $loop->have_posts() ): while ( $loop->have_posts() ): $loop->the_post();

    global $product;

    wp_set_object_terms($product, array('nou'), 'product_tag');

endwhile; endif; wp_reset_postdata();

}

本文标签: woocommerce offtopicAdd quotnewquot tag for existing products