Created
March 10, 2017 17:00
-
-
Save Tomasz-Silpion/fd3727b95b22409dc505368099f7d1fd to your computer and use it in GitHub Desktop.
Fix Woocommerce stock to match qty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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