title: How to set all featured products to none featured and then select random products and set them as featured
body: <p>I am trying to create a script outside WordPress that will set automatically all featured products to none featured and then select 8 random products and set them as featured.</p>
  <p>I am working on that part where I fetch featured products IDs and then set them as none featured, but the desired result is not forthcoming, any advice?</p>
  <pre class="lang-php prettyprint-override"><code>require $_SERVER['DOCUMENT_ROOT'].'/wp-config.php';
  global $wpdb;
  
  global $product;
  $args = array(
      'post_type'           =&gt; 'product',
      'posts_per_page'      =&gt; $products,
      'orderby'             =&gt; $orderby,
      'order'               =&gt; $order == 'asc' ? 'asc' : 'desc',
      'post__in'            =&gt; wc_get_featured_product_ids(),
  );
  
  $query = new WP_Query( $args );
  
  if ( $query-&gt;have_posts() ): while ( $query-&gt;have_posts() ): $query-&gt;the_post();
  
      $product = wc_get_product( $query-&gt;post-&gt;ID );
      $product-&gt;set_featured(false);
      $product-&gt;save();
  
  endwhile; wp_reset_query();endif;
  </code></pre>