This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Question regarding custom fields for WooCommerce

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Question regarding custom fields for WooCommerce Reply To: Question regarding custom fields for WooCommerce

#29832
Ernest MarcinkoErnest Marcinko
Keymaster

Maybe this variation:

add_filter( 'asp_results', 'asp_add_pc_titles', 10, 1 );
function asp_add_pc_titles( $results ) {
  $taxonomy = "product_cat";
  
  foreach ($results as $k=>&$r) {
	if ( isset($r->post_type) ) {
		// Get the post categories
		$post_terms = wp_get_object_terms( $r->id, $taxonomy );
		$cats = array();         
		if ( !empty($post_terms) && !is_wp_error($post_terms) ) {
		  // Concatenate category names to the $cats variable
		  foreach($post_terms as $c){
			  $cats[] = '<a href="'.get_term_link($c->term_id, $taxonomy).'">' . $c->name . '</a>';
		  }
		}          
	 
		// Modify the post title
		if ( !empty($cats) )
		  $r->content  .= "<br>Categories: ".implode(', ', $cats);
		  
	}  
  }
 
  return $results;
}