From 2ad4592324be1c908d671ba761e6a03247388c80 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 10 Aug 2015 18:18:33 -0300 Subject: [PATCH] WooCommerce 2.4.1 update script --- includes/updates/woocommerce-update-2.4.1.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 includes/updates/woocommerce-update-2.4.1.php diff --git a/includes/updates/woocommerce-update-2.4.1.php b/includes/updates/woocommerce-update-2.4.1.php new file mode 100644 index 00000000000..6fac0cbe4cb --- /dev/null +++ b/includes/updates/woocommerce-update-2.4.1.php @@ -0,0 +1,37 @@ +get_results( " + SELECT DISTINCT posts.ID AS variation_id, posts.post_parent AS variation_parent + FROM {$wpdb->posts} as posts + LEFT OUTER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id AND postmeta.meta_key = '_stock_status' + WHERE posts.post_type = 'product_variation' + AND postmeta.meta_value IS NULL +" ); + +$rates = WC_Tax::get_rates(); +$transient_version = WC_Cache_Helper::get_transient_version( 'product' ); + +foreach ( $update_variations as $variation ) { + $parent_stock_status = get_post_meta( $variation->variation_parent, '_stock_status', true ); + add_post_meta( $variation->variation_id, '_stock_status', $parent_stock_status ? $parent_stock_status : 'instock', true ); + delete_transient( 'wc_product_children_' . $variation->variation_parent ); + delete_transient( 'wc_var_prices' . md5( json_encode( array( + $variation->variation_parent, + $rates, + $transient_version + ) ) ) ); +}