wc_update_220_attributes

The WooCommerce wc update 220 attributes function.

Description

wc_update_220_attributes(); 

Usage

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

Defined (1)

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

/includes/wc-update-functions.php  
  1. function wc_update_220_attributes() { 
  2. global $wpdb; 
  3. // Update taxonomy names with correct sanitized names 
  4. $attribute_taxonomies = $wpdb->get_results( "SELECT attribute_name, attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies" ); 
  5.  
  6. foreach ( $attribute_taxonomies as $attribute_taxonomy ) { 
  7. $sanitized_attribute_name = wc_sanitize_taxonomy_name( $attribute_taxonomy->attribute_name ); 
  8. if ( $sanitized_attribute_name !== $attribute_taxonomy->attribute_name ) { 
  9. if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT 1=1 FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $sanitized_attribute_name ) ) ) { 
  10. // Update attribute 
  11. $wpdb->update( 
  12. "{$wpdb->prefix}woocommerce_attribute_taxonomies",  
  13. array( 
  14. 'attribute_name' => $sanitized_attribute_name,  
  15. ),  
  16. array( 
  17. 'attribute_id' => $attribute_taxonomy->attribute_id,  
  18. ); 
  19.  
  20. // Update terms 
  21. $wpdb->update( 
  22. $wpdb->term_taxonomy,  
  23. array( 'taxonomy' => wc_attribute_taxonomy_name( $sanitized_attribute_name ) ),  
  24. array( 'taxonomy' => 'pa_' . $attribute_taxonomy->attribute_name ) 
  25. );