wc_update_300_grouped_products

The WooCommerce wc update 300 grouped products function.

Description

wc_update_300_grouped_products(); 

Usage

  1. if ( !function_exists( 'wc_update_300_grouped_products' ) ) { 
  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_300_grouped_products(); 
  7.  

Defined (1)

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

/includes/wc-update-functions.php  
  1. function wc_update_300_grouped_products() { 
  2. global $wpdb; 
  3. $parents = $wpdb->get_col( "SELECT DISTINCT( post_parent ) FROM {$wpdb->posts} WHERE post_parent > 0 AND post_type = 'product';" ); 
  4. foreach ( $parents as $parent_id ) { 
  5. $parent = wc_get_product( $parent_id ); 
  6. if ( $parent && $parent->is_type( 'grouped' ) ) { 
  7. $children_ids = get_posts( array( 
  8. 'post_parent' => $parent_id,  
  9. 'posts_per_page' => -1,  
  10. 'post_type' => 'product',  
  11. 'fields' => 'ids',  
  12. ) ); 
  13. update_post_meta( $parent_id, '_children', $children_ids ); 
  14.  
  15. // Update children to remove the parent. 
  16. $wpdb->update( 
  17. $wpdb->posts,  
  18. array( 
  19. 'post_parent' => 0,  
  20. ),  
  21. array( 
  22. 'post_parent' => $parent_id,  
  23. );