wc_update_241_variations

The WooCommerce wc update 241 variations function.

Description

wc_update_241_variations(); 

Usage

  1. if ( !function_exists( 'wc_update_241_variations' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-update-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_update_241_variations(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-update-functions.php  
  1. function wc_update_241_variations() { 
  2. global $wpdb; 
  3.  
  4. // Select variations that don't have any _stock_status implemented on WooCommerce 2.2 
  5. $update_variations = $wpdb->get_results( " 
  6. SELECT DISTINCT posts.ID AS variation_id, posts.post_parent AS variation_parent 
  7. FROM {$wpdb->posts} as posts 
  8. LEFT OUTER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id AND postmeta.meta_key = '_stock_status' 
  9. WHERE posts.post_type = 'product_variation' 
  10. AND postmeta.meta_value IS NULL 
  11. " ); 
  12.  
  13. foreach ( $update_variations as $variation ) { 
  14. // Get the parent _stock_status 
  15. $parent_stock_status = get_post_meta( $variation->variation_parent, '_stock_status', true ); 
  16.  
  17. // Set the _stock_status 
  18. add_post_meta( $variation->variation_id, '_stock_status', $parent_stock_status ? $parent_stock_status : 'instock', true ); 
  19.  
  20. // Delete old product children array 
  21. delete_transient( 'wc_product_children_' . $variation->variation_parent ); 
  22.  
  23. // Invalidate old transients such as wc_var_price 
  24. WC_Cache_Helper::get_transient_version( 'product', true );