Reply To: Display woocommerce product id in results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Display woocommerce product id in results Reply To: Display woocommerce product id in results

#11436
Ernest Marcinko
Ernest Marcinko
Keymaster

Hi!

Happy new year to you too!

It depends on where you want to use the link. In case you want to add a link to the results content, you can do it by a filter, as a sample:

add_filter( 'asp_results', 'asp_my_custom_handler', 1, 1 );
  
function asp_my_custom_handler( $results ) {
 
  foreach ($results as $k=>&$r) {
    if ($r->content_type != "pagepost") continue;
    /**
     * $r is the corrent result object
     * $r->id holds the product ID
     * $r->content holds the result content output
     * $r->title holds the result title
     * $r->link holds the result permalink
     */                             
    // For example adding something to the content
    $r->content .= ' My custom content.';
  }
  
  return $results;
}

In this case the $r->id is the product ID.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)