## woocommerce offtopic – Add “new” tag for existing products

Question

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();


}

0
1 month 2021-06-29T09:50:46-05:00 0 Answers 0 views 0