Create WooCommerce Category in PHP
-
Hello,
So i have a piece of code:
for ($i=0; $i < $nblignes; $i++) { $niv = round($niveau[$i]); $lib = $libelle[$i]; if ($niv == 1) { $id = substr($lib, 0, 4); $parent = substr($lib, 0, 2); $cat_name = substr($lib, 7); $catarr = array( 'term_id' => $id, 'name' => $cat_name, 'parent' => $parent, 'taxonomy' => 'product_cat', 'slug' => $cat_name, 'description' => $cat_name ); update_term_meta( $id, 'product_cat', $catarr, $prev_value = '' ); echo $id.' | '.$parent.' | '.$cat_name.'<br>'; } if ($niv == 2) { $id = substr($lib, 0, 2); $parent = substr($lib, 0, 1); $cat_name = substr($lib, 5); $catarr = array( 'term_id' => $id, 'name' => $cat_name, 'parent' => $parent, 'taxonomy' => 'product_cat', 'slug' => $cat_name, 'description' => $cat_name ); update_term_meta( $id, 'product_cat', $catarr, $prev_value = '' ); echo $id.' | '.$parent.' | '.$cat_name.'<br>'; } if ($niv == 3) { $id = substr($lib, 0, 1); $parent = ''; $cat_name = substr($lib, 4); $catarr = array( 'term_id' => $id, 'name' => $cat_name, 'parent' => $parent, 'taxonomy' => 'product_cat', 'slug' => $cat_name, 'description' => $cat_name ); update_term_meta( $id, 'product_cat', $catarr, $prev_value = '' ); echo $id.' | '.$parent.' | '.$cat_name.'<br>'; }
The thing is, it works (category are well created in wp_termmeta), but categories doesn’t appear in woocommerce categories area in wordpress. So i think update_term_meta is not a good way to do it … or am i missing something ?
Thanks for your help !
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Create WooCommerce Category in PHP’ is closed to new replies.