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

Display woocommerce product id in results

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #11428
    Jeffrey ZhangNumaphon
    Participant

    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

    #11436
    Ernest MarcinkoErnest 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:

    [php]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;
    }[/php]

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

    #11455
    Jeffrey ZhangNumaphon
    Participant

    Thanks a lot, it works fine !

    #11464
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.