wc_update_220_variations

The WooCommerce wc update 220 variations function.

Description

wc_update_220_variations(); 

Usage

  1. if ( !function_exists( 'wc_update_220_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_220_variations(); 
  7.  

Defined (1)

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

/includes/wc-update-functions.php  
  1. function wc_update_220_variations() { 
  2. global $wpdb; 
  3. // Update variations which manage stock 
  4. $update_variations = $wpdb->get_results( " 
  5. SELECT DISTINCT posts.ID AS variation_id, posts.post_parent AS variation_parent FROM {$wpdb->posts} as posts 
  6. LEFT OUTER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id AND postmeta.meta_key = '_stock' 
  7. LEFT OUTER JOIN {$wpdb->postmeta} as postmeta2 ON posts.ID = postmeta2.post_id AND postmeta2.meta_key = '_manage_stock' 
  8. WHERE posts.post_type = 'product_variation' 
  9. AND postmeta.meta_value IS NOT NULL 
  10. AND postmeta.meta_value != '' 
  11. AND postmeta2.meta_value IS NULL 
  12. " ); 
  13.  
  14. foreach ( $update_variations as $variation ) { 
  15. $parent_backorders = get_post_meta( $variation->variation_parent, '_backorders', true ); 
  16. add_post_meta( $variation->variation_id, '_manage_stock', 'yes', true ); 
  17. add_post_meta( $variation->variation_id, '_backorders', $parent_backorders ? $parent_backorders : 'no', true );