'Woocommerce set all products to featured products from mysql query

I have a woocommerce store and I try to select from Mysql all products and set them as "Featured" products or set them as Non "Featured" products.

I have found the following query that set post_status to whatever I want. I quess that I just have to replace post_status to something else that set products as "featured" products or as no "featured" product.

UPDATE wp_posts 
SET post_status = 'Published' 
AND post_type = 'product'
OR post_type = 'product_variation'


Solution 1:[1]

Is there a reason you want to hack this into the MySQL database directly? The proper approach would be to use the WC API in order to do so.

An example that uses an array of WC products:

foreach ( $products as $product ) {
    $productObj = $product->get_product();
    $productObj->set_featured(true);
    $productObj->save();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 reddfox