Display woocommerce product id in results

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 Ernest Marcinko 5 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #11428
    Jeffrey Zhang
    Numaphon
    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 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 :)


    #11455
    Jeffrey Zhang
    Numaphon
    Participant

    Thanks a lot, it works fine !

    #11464
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.