wc_update_300_product_visibility

Convert meta values into term for product visibility.

Description

wc_update_300_product_visibility(); 

Usage

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

Defined (1)

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

/includes/wc-update-functions.php  
  1. function wc_update_300_product_visibility() { 
  2. global $wpdb; 
  3.  
  4. WC_Install::create_terms(); 
  5.  
  6. if ( $featured_term = get_term_by( 'name', 'featured', 'product_visibility' ) ) { 
  7. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_featured' AND meta_value = 'yes';", $featured_term->term_taxonomy_id ) ); 
  8.  
  9. if ( $exclude_search_term = get_term_by( 'name', 'exclude-from-search', 'product_visibility' ) ) { 
  10. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_visibility' AND meta_value IN ('hidden', 'catalog');", $exclude_search_term->term_taxonomy_id ) ); 
  11.  
  12. if ( $exclude_catalog_term = get_term_by( 'name', 'exclude-from-catalog', 'product_visibility' ) ) { 
  13. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_visibility' AND meta_value IN ('hidden', 'search');", $exclude_catalog_term->term_taxonomy_id ) ); 
  14.  
  15. if ( $outofstock_term = get_term_by( 'name', 'outofstock', 'product_visibility' ) ) { 
  16. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_stock_status' AND meta_value = 'outofstock';", $outofstock_term->term_taxonomy_id ) ); 
  17.  
  18. if ( $rating_term = get_term_by( 'name', 'rated-1', 'product_visibility' ) ) { 
  19. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 1;", $rating_term->term_taxonomy_id ) ); 
  20.  
  21. if ( $rating_term = get_term_by( 'name', 'rated-2', 'product_visibility' ) ) { 
  22. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 2;", $rating_term->term_taxonomy_id ) ); 
  23.  
  24. if ( $rating_term = get_term_by( 'name', 'rated-3', 'product_visibility' ) ) { 
  25. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 3;", $rating_term->term_taxonomy_id ) ); 
  26.  
  27. if ( $rating_term = get_term_by( 'name', 'rated-4', 'product_visibility' ) ) { 
  28. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 4;", $rating_term->term_taxonomy_id ) ); 
  29.  
  30. if ( $rating_term = get_term_by( 'name', 'rated-5', 'product_visibility' ) ) { 
  31. $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 5;", $rating_term->term_taxonomy_id ) );