Forked from codearachnid/woocommerce_update_stock_status.php
Last active
February 3, 2017 03:28
-
-
Save crisweiser/a322f1bf0e6edc183c9e to your computer and use it in GitHub Desktop.
Change Woocommerce Stock Status
This file contains 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 | |
/** | |
* set the stock status for all products in your WooCommerce store | |
* $from is the searched value | |
* $signal is the operator (< or > ..) | |
* $to is the target to be defined | |
* @return void | |
*/ | |
function woocommerce_update_stock_status($from,$signal,$to){ | |
global $wpdb; | |
// set all status for products with 0 or less stocked quantity | |
$sql = "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_stock' AND meta_value $signal $from ) id SET stock.meta_value = '$to' WHERE stock.post_id = id.post_id AND stock.meta_key = '_stock_status';"; | |
// run queries | |
$wpdb->query( $sql ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment