Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 15th, 2013  |  syntax: PHP  |  size: 0.71 KB  |  views: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2.                 //link the product to the category
  3.                 $cats = explode ( '|', $data[3] );
  4.                 foreach ($cats as $cat){
  5.                         $cat_taxs = explode( '->', $cat );
  6.                         $parent = false;
  7.                         foreach ( $cat_taxs as $cat_tax)
  8.                         {
  9.                                 $new_cat = term_exists( $cat_tax, 'product_cat' );
  10.                                 if ( ! is_array( $new_cat ) ) {
  11.                                         $new_cat = wp_insert_term(      $cat_tax, 'product_cat', array( 'slug' => $cat_tax, 'parent'=> $parent) );
  12.                                 }
  13.                                 $x = wp_set_object_terms( $post_id, (int)$new_cat['term_id'], 'product_cat', true );
  14.                                 $parent = $new_cat['term_id'];
  15.                                
  16.                                 //check out http://wordpress.stackexchange.com/questions/24498/wp-insert-term-parent-child-problem
  17.                                 delete_option("product_cat_children");
  18.                         }
  19.                         unset($parent);
  20.                 }
clone this paste RAW Paste Data