woocommerce/includes/updates/woocommerce-update-2.4.1.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2015-08-10 21:18:33 +00:00
<?php
/**
* Update WC to 2.4.1
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Updates
* @version 2.4.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $wpdb;
2015-08-10 21:23:28 +00:00
// Select variations that don't have any _stock_status implemented on WooCommerce 2.2
2015-08-10 21:18:33 +00:00
$update_variations = $wpdb->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
" );
foreach ( $update_variations as $variation ) {
2015-08-10 21:23:28 +00:00
// Get the parent _stock_status
2015-08-10 21:18:33 +00:00
$parent_stock_status = get_post_meta( $variation->variation_parent, '_stock_status', true );
2015-08-10 21:23:28 +00:00
// Set the _stock_status
2015-08-10 21:18:33 +00:00
add_post_meta( $variation->variation_id, '_stock_status', $parent_stock_status ? $parent_stock_status : 'instock', true );
2015-08-10 21:23:28 +00:00
// Delete old product children array
2015-08-10 21:18:33 +00:00
delete_transient( 'wc_product_children_' . $variation->variation_parent );
}
2015-08-10 21:23:28 +00:00
2015-08-10 21:26:06 +00:00
// Invalidate old transients such as wc_var_price
2015-08-10 21:23:28 +00:00
WC_Cache_Helper::get_transient_version( 'product', true );