includes/admin/create-products.php
##This function is used to assign categories to articles
This function is used to assign categories to articles
This function is used to assign categories to articles
public function add_category($category1,$category2,$category3){
		$return = array();
		global $wc_arcavis_shop;
		try{
			$category1=trim(str_replace('  ',' ', str_replace('&','&amp;',$category1)));
			$category2=trim(str_replace('  ',' ', str_replace('&','&amp;',$category2)));
			$category3=trim(str_replace('  ',' ', str_replace('&','&amp;',$category3)));
			$category1_exist = term_exists( $category1, 'product_cat' );
			if($category1_exist){
				$return[] = $category1_exist['term_id'];
				$parent_term_id = $category1_exist['term_id'];
			}else{
				$category1_array = wp_insert_term(
					$category1, 
					'product_cat', 
					array(		        
						'slug' => strtolower(str_replace(" ", "-", $category1)),		        
					)
				);
				$return[] = $category1_array['term_id'];
				$parent_term_id = $category1_array['term_id'];
			}
			if($category2 != ''){
				$category2_exist = term_exists( $category2, 'product_cat' );
				if($category2_exist){
					$return[] = $category2_exist['term_id'];
					$parent_term_id2 = $category2_exist['term_id'];
				}else{
					$category2_array = wp_insert_term(
						$category2, 
						'product_cat', 
						array(
							'slug' => strtolower(str_replace(" ", "-", $category2)),
							'parent'=> $parent_term_id
						)
					);
					$return[] = $category2_array['term_id'];
					$parent_term_id2 = $category2_array['term_id'];
				}
			}
			if($category3 != ''){
				$category3_exist = term_exists( $category3, 'product_cat' );
				if($category3_exist){
					$return[] = $category3_exist['term_id'];
				}else{
					$category3_array = wp_insert_term(
						$category3, 
						'product_cat', 
						array(
							'slug' => strtolower(str_replace(" ", "-", $category3)),
							'parent'=> $parent_term_id2
						)
					);
					$return[] = $category3_array['term_id'];
				}
			}
			return $return;
		}catch (Exception $e) 
		{
			$wc_arcavis_shop->logError('add_category '.$e->getMessage());		
			return $return;
		}
	}
public function add_category ( $ category1 , $ category2 , $ category3 ) { $ return = array ( ) ; global $ wc_arcavis_shop ; try { $ category1 = trim ( str_replace ( '  ' , ' ' , str_replace ( '&' , '&amp;' , $ category1 ) ) ) ; $ category2 = trim ( str_replace ( '  ' , ' ' , str_replace ( '&' , '&amp;' , $ category2 ) ) ) ; $ category3 = trim ( str_replace ( '  ' , ' ' , str_replace ( '&' , '&amp;' , $ category3 ) ) ) ; $ category1_exist = term_exists ( $ category1 , 'product_cat' ) ; if ( $ category1_exist ) { $ return [ ] = $ category1_exist [ 'term_id' ] ; $ parent_term_id = $ category1_exist [ 'term_id' ] ; } else { $ category1_array = wp_insert_term ( $ category1 , 'product_cat' , array ( 'slug' => strtolower ( str_replace ( " " , " - " , $ category1 ) ) , ) ) ; $ return [ ] = $ category1_array [ 'term_id' ] ; $ parent_term_id = $ category1_array [ 'term_id' ] ; } if ( $ category2 != '' ) { $ category2_exist = term_exists ( $ category2 , 'product_cat' ) ; if ( $ category2_exist ) { $ return [ ] = $ category2_exist [ 'term_id' ] ; $ parent_term_id2 = $ category2_exist [ 'term_id' ] ; } else { $ category2_array = wp_insert_term ( $ category2 , 'product_cat' , array ( 'slug' => strtolower ( str_replace ( " " , " - " , $ category2 ) ) , 'parent' => $ parent_term_id ) ) ; $ return [ ] = $ category2_array [ 'term_id' ] ; $ parent_term_id2 = $ category2_array [ 'term_id' ] ; } } if ( $ category3 != '' ) { $ category3_exist = term_exists ( $ category3 , 'product_cat' ) ; if ( $ category3_exist ) { $ return [ ] = $ category3_exist [ 'term_id' ] ; } else { $ category3_array = wp_insert_term ( $ category3 , 'product_cat' , array ( 'slug' => strtolower ( str_replace ( " " , " - " , $ category3 ) ) , 'parent' => $ parent_term_id2 ) ) ; $ return [ ] = $ category3_array [ 'term_id' ] ; } } return $ return ; } catch ( Exception $ e ) { $ wc_arcavis_shop -> logError ( 'add_category ' . $ e -> getMessage ( ) ) ; return $ return ; } }
This function is used to assign categories to articles
This function is used to assign categories to articles
// the term  // the taxonomy // the term  // the taxonomy // the term  // the taxonomy