Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

woocommerce get product id by category id

$p_array=['12','16', '21', '17'];
$prod_array= array();
foreach( $p_array as $key=>$value) {

			$term_object = get_term( $value );
			$cat_name= $term_object->slug;
			//echo $cat_name;
			$all_ids = get_posts( array(
				'post_type' => 'product',
				'numberposts' => -1,
				'post_status' => 'publish',
				'fields' => 'ids',
				'tax_query' => array(
					array(
						'taxonomy' => 'product_cat',
						'field' => 'slug',
						'terms' => $cat_name,
						'operator' => 'IN',
					)
				),
			) );
			foreach ( $all_ids as $id ) {
				array_push($prods_array, $id);
			}
		 }
        print_r($prod_array); 
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #woocommerce #product #id #category #id
ADD COMMENT
Topic
Name
9+9 =