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
October 15, 2020 at 1:56 pm
#29827
Keymaster
Nope, that has to be done programatically. I found something similar I suggested to someone else:
Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
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 $pageposts;
}
This may not work anymore though.