我的woocommerce安装中的库存状态是由另一个插件(square)上传的,因此所有商品都有库存,即使数量为0。有没有办法让状态以某种方式重置,以便库存为0的产品的库存状态为“缺货”。
我已经找到了这个,发现了以下内容function
function jolie_theme_child_reset_stock_status(){
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 < 1 ) id SET stock.meta_value = \'outofstock\' WHERE stock.post_id = id.post_id AND stock.meta_key = \'_stock_status\';";
// set all status for products with stock.
$sql .= "UPDATE $wpdb->postmeta stock, (SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = \'_stock\' AND meta_value > 0 ) id SET stock.meta_value = \'outofstock\' WHERE stock.post_id = id.post_id AND stock.meta_key = \'_stock_status\';";
// run queries
$wpdb->query( $sql );
}
但如果我运行此命令,则会导致服务器500错误。使用或不使用上述代码重置库存状态的简单方法是什么?