wc_taxonomy_metadata_update_content_for_split_terms

When a term is split, ensure meta data maintained.

Description

wc_taxonomy_metadata_update_content_for_split_terms( (int) $old_term_id, (int) $new_term_id, (string) $term_taxonomy_id, (string) $taxonomy ); 

Parameters (4)

0. $old_term_id (int)
The old term id.
1. $new_term_id (int)
The new term id.
2. $term_taxonomy_id (string)
The term taxonomy id.
3. $taxonomy (string)
The taxonomy.

Usage

  1. if ( !function_exists( 'wc_taxonomy_metadata_update_content_for_split_terms' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-term-functions.php'; 
  3.  
  4. // The old term id. 
  5. $old_term_id = -1; 
  6.  
  7. // The new term id. 
  8. $new_term_id = -1; 
  9.  
  10. // The term taxonomy id. 
  11. $term_taxonomy_id = ''; 
  12.  
  13. // The taxonomy. 
  14. $taxonomy = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wc_taxonomy_metadata_update_content_for_split_terms($old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy); 
  18.  

Defined (1)

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

/includes/wc-term-functions.php  
  1. function wc_taxonomy_metadata_update_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 
  2. global $wpdb; 
  3.  
  4. if ( get_option( 'db_version' ) < 34370 ) { 
  5. if ( 'product_cat' === $taxonomy || taxonomy_is_product_attribute( $taxonomy ) ) { 
  6. $old_meta_data = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->prefix}woocommerce_termmeta WHERE woocommerce_term_id = %d;", $old_term_id ) ); 
  7.  
  8. // Copy across to split term 
  9. if ( $old_meta_data ) { 
  10. foreach ( $old_meta_data as $meta_data ) { 
  11. $wpdb->insert( 
  12. "{$wpdb->prefix}woocommerce_termmeta",  
  13. array( 
  14. 'woocommerce_term_id' => $new_term_id,  
  15. 'meta_key' => $meta_data->meta_key,  
  16. 'meta_value' => $meta_data->meta_value,  
  17. );