1
votes

In WooCommerce, my product variations are disabled so the item appear out of stock despite they are in stock.

I need some help to enable this option in all of my woocommerce product variations.

I want to enable the checkbox where it appears the text "enable" can we enable that box for all the products via SQL code:

i want to enable the checkbox where it appears the text "enable" can we enable that box for all the products via SQL code

For clarifications see this screenshot:

click this image here for more clarifying

1
Please any feed back on the answer below will be appreciated. - LoicTheAztec

1 Answers

0
votes

You can run this very simple SQL query on phpMyAdmin that will enable all disabled variations (always do a database backup before - Also check that your table start with wp_):

UPDATE wp_posts as p
SET p.post_status = 'publish'
WHERE p.post_status = 'private'
AND p.post_type = 'product_variation';

Or you can use this custom function that you will run once by browsing any page of your web site (always do a database backup before):

function enable_all_disabled_variations(){
    global $wpdb;
    
    return $wpdb->query("
        UPDATE {$wpdb->prefix}posts as p
        SET p.post_status = 'publish'
        WHERE p.post_status = 'private'
        AND p.post_type = 'product_variation'
    ");
}
// Run the function
enable_all_disabled_variations();

Code goes in functions.php file of your active child theme (or active theme). Tested and works. Once done remove this code.