Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Display woocommerce product id in results
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 6 years, 11 months ago.
- AuthorPosts
- December 31, 2016 at 4:22 pm #11428
Hello,
My website is a woocommerce shop and the plugin is only searching in the products. Everything works fine, however, I can’t seem to be able to retrieve the product id in the results, I’d like to display it in a link. Is there a shortcode I didn’t find thatallows to do it, or could you tell me the way to procede ?
Happy new year to you !
Regards,
Mr Camille Prioul
January 3, 2017 at 2:14 pm #11436Hi!
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 :)
January 4, 2017 at 3:36 pm #11455Thanks a lot, it works fine !
January 5, 2017 at 9:39 am #11464You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.