add_action() for $product->get_date_created

I have a code that set "new" tag for products. I want to set that tag for products that have less than 14 days. I used for call the function add_action('init', 'name_fct');, but I get an error, I tried with add_action('wp_enqueue_scripts', 'name_fct');, but doesn’t work. Please help me to develop my code to work. My code is:

function display_new_loop_woocommerce() {  $  args = array(     'post_type' => 'product', // your product post type     'posts_per_page' => - 1, );  $  posts = get_posts($  args);  foreach ($  posts as $  post):     setup_postdata($  post);      $  post->get_date_created();          //here I want to verify if the product has less than 14 days     if( ! has_term( '', 'product_tag', $  post->ID ) ) :         wp_set_object_terms($  post->ID, array('nou'), 'product_tag');     endif;      wp_reset_postdata(); endforeach; }