Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix Woocommerce stock to match qty
<?php
define('WP_USE_THEMES', false);
require('./wp-load.php');
$args = array('post_type' => 'product', 'posts_per_page' => -1);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
$qty = get_post_meta(get_the_ID(), '_stock', true);
$status = get_post_meta(get_the_ID(), '_stock_status', true);
if ($qty > 0 && $status == "outofstock") {
update_post_meta(get_the_ID(), '_stock_status', 'in_stock', $status);
echo sprintf("%s qty was %s, status was %s. Fixed stock to instock", get_the_title(), $qty, $status);
echo "<br>";
}
endwhile;
wp_reset_query();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.