Setting the 1st Gallery Image as Default Drop down image

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Setting the 1st Gallery Image as Default Drop down image

This topic contains 7 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 month ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #37484
    lombardibenny
    lombardibenny
    Participant

    Hi we just bought your plugin, I have spent many hours trying to configure the search to retrieve the first gallery image as the drop down image but to no avail. I was wondering if you would know what selector to use or if it’s even possible to get the Ajax to retreive the first image in the gallery. See: https://sugatsune.ca/product/3-way-adjustable-concealed-hinge-for-cladded-doors-black

    Thank you for taking the time, please let us know what we are doing wrong or if its possible to set that image.

    Please example of what we are trying to do: https://imgur.com/a/ojW8U1N

    Thanks

    Attachments:
    You must be logged in to view attached files.
    #37498
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    That is a tough one, it depends on how that gallery is appended to the actual content. I assume it might be a shortcode of some sort. In that case, try turning on this option, to see if it changes anything.

    Best,
    Ernest Marcinko

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


    #37502
    lombardibenny
    lombardibenny
    Participant

    Hi no I tried that, the previous developer built the site in ACF I saw this in your troubleshooting guide and gave it try. Doesn’t work unfortunately. I have been trying to get it to work using the custom fields containing image term. Am I barking down the wrong tree here?

    Searching HES I found the the search actually draws in the first galley image sometimes, but it doesn’t do it consistently for all. Is there a way to pinpoint the setting?

    This product is showing first image gallery, See: https://staging5.sugatsune.ca/product/glass-door-bracket-for-hes3d-9-3/
    Search: HES

    Thank you for your time.

    Attachments:
    You must be logged in to view attached files.
    #37516
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Well, those may not be coming from the actual gallery, the imge URLs are different in the page source, and in the search.
    Can you check if on any of those posts there is a featured image set perhaps? Maybe that is the one, the plugin actually fetched.

    If the option I suggested did not work, then then this may not be possible. I suspect the gallery may not be rendered only on an actual pageview, so the plugin can’t “see” the images in the page source.

    I can double check the configuration if you want to, however I could not find a way to log-in. Is there a URL I need to visit for that?

    The custom field you tried there will not work that way. The field has to be an image field, or a text field containing the image. I guess the gallery is some sort of a section/object or a complex repeater field of some sort.

    Best,
    Ernest Marcinko

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


    #37527
    lombardibenny
    lombardibenny
    Participant

    Sorry Ernest the log in url is: https://staging5.sugatsune.ca/lampstaff/
    (credentials are attached at the top)
    Please can you check for us. I am will to pay you for your time to get this to work.

    #37533
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I think I actually managed to find a possible solution. I did a bit of research and placed this custom code to the functions.php file in your theme directory:

    // Ajax Search Pro - Getting the first WooCommerce gallery image as the featured image
    add_filter( 'asp_results', 'asp_get_woocommerce_gallery_first_image', 10, 1 );
    function asp_get_woocommerce_gallery_first_image( $results ) {
      foreach ($results as $k=>&$r) { 
        if ( isset($r->post_type) && $r->post_type == 'product' ) {
    		$product = wc_get_product($r->id);
    		$attachment_ids = $product->get_gallery_image_ids();
    		if ( isset($attachment_ids[0]) ) {
    			$r->image = wp_get_attachment_url( $attachment_ids[0] );
    		}
        } 
      } 
      return $results;
    }

    From what I can see, where the gallery is available, I am seeing the first image as the results featured image.

    Best,
    Ernest Marcinko

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


    #37539
    lombardibenny
    lombardibenny
    Participant

    FANTASTIC! Thank you so much. We will make sure to review you on Code Canyon. Really appreciate your work.

    #37541
    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 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.