How to add image source into a custom field?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to add image source into a custom field?

This topic contains 15 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #32334
    codigo3net85
    codigo3net85
    Participant

    Hello, im contacting you to know how to add image source a custom field. How to get the information.
    Im using YITH Mult Vendor / marketplace plugin, each vendor can upload an AVATAR (like logo) for their stores. I need to know how to make that the image be loaded that avatar the shop vendor uploaded and be shown in Ajax Search Pro.

    In Ajax Search Pro the instance is: Tiendas

    Here you can see in frontend my tests https://www.voydecompras.mx/stores/

    Also i want to know how to make when i select in a search settings option a category or a tag to show all of the Stores that are related to those categories / tags selected. For example, if i select FLORES category, will show only Stores that are related to Categorie Flores.

    I hope i have explained myself correctly.
    Thank you.

    #32346
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    It is a tough one, the image is probably not stored as term meta. I tried various different fields, but they were all empty. Let me know if there is an API for the Yith vendors plugin – namely a function which can return the image URL based on the vendor ID. I can then suggest a possible custom code to parse the image.

    Best,
    Ernest Marcinko

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


    #32376
    codigo3net85
    codigo3net85
    Participant

    Hello Ernst!
    YITH Multi Vendor plugin has no API =(

    Uff.. I’m already regretting buying the YITH Multi Vendor plugin. It is lack of tons of things.

    Thank you.

    #32387
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    That’s a shame. Try asking their support, they might be able to suggest something, I’m sure there is a way to get those images by the the taxonomy term IDs easily.

    Best,
    Ernest Marcinko

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


    #32499
    codigo3net85
    codigo3net85
    Participant

    Hello Ernest! I contacted YITH support about how to get avatar image from a Vendor from YITH Multivendor Store plugin.

    Here is what they told me:

    Hi Daniel,
    thanks for contacting us. The plugin can use two type of avatar: Owner Avatar or Custom avatar and you can use this code to get it:

    wp_get_attachment_image( $vendor->avatar, apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) ) );
    
    OR
    
    get_avatar( $vendor->owner, get_option( 'yith_vendors_gravatar_image_size', '62' ) );

    If you need other kind of information about that feel free to contact me again.
    Have a nice day
    Andrea Grillo

    Could you please help me to know how to “convert” this codes they gave me to a readable way for Ajax Searc Pro so it can get the Avatar Image please?

    Thank you!

    #32504
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    That looks great, but still a bit of information is missing.

    How do we get the $vendor object by the taxonomy term ID? Once we got that, it should get very easy.

    Best,
    Ernest Marcinko

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


    #32535
    codigo3net85
    codigo3net85
    Participant

    Hello! Here is what YITH support told me about how to get $vendor

    Hi Daniel,
    you can use this:

    $vendor = yith_get_vendor( $term_id, ‘vendor’ );

    and in add you can check if this is a valid vendor with this method

    $vendor->is_valid()

    Is this enough Ernest to get image from vendor and be shown in your ASP plugin?
    Thanks

    #32544
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    That sounds perfect!

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter('asp_results', 'asp_results_add_custom_image', 10, 1);
    function asp_results_add_custom_image($results) {
    	foreach ( $results as $k => &$r ) {
    		if ( isset($r->taxonomy) ) {
    			$vendor = yith_get_vendor( $r->id, 'vendor' );
    			$r->image = wp_get_attachment_image_src( 
    				$vendor->avatar, 
    				apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) )  
    			);
    		}
    	}
    	
    	return $results;
    }

    If all the code they mentioned was right, this should very likely work.

    Best,
    Ernest Marcinko

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


    #32548
    codigo3net85
    codigo3net85
    Participant

    Hello! Thank you for your respose and your code!
    But, i dont know if im missing something, i dont know if i need to modify anything else in the ASP settings. I already added your code in my child theme functions.php and check what happens, i recorded a video for you so you can see it:

    https://www.awesomescreenshot.com/video/3262819?key=18580192a1328262794efe4e02254acd

    In few words, after adding the code in functions.php no results are found in ASP, if i remove the code, results appears again (without image of course).

    Any advice for this?
    Thanks!

    #32550
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Try this variation, maybe this one:

    add_filter('asp_results', 'asp_results_add_custom_image', 10, 1);
    function asp_results_add_custom_image($results) {
    	foreach ( $results as $k => &$r ) {
    		if ( isset($r->taxonomy) ) {
    			$vendor = yith_get_vendor( $r->id, 'vendor' );
    			$r->image = wp_get_attachment_image_src( 
    				$vendor->avatar, 
    				apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) )  
    			);
    		}
    	}
    	
    	return $results;
    }
    Best,
    Ernest Marcinko

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


    #32551
    codigo3net85
    codigo3net85
    Participant

    Wow! thanks for your mega fast response!
    Now im getting blank images, see attached screenshot please

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

    Tough one, maybe this one:

    add_filter('asp_results', 'asp_results_add_custom_image', 10, 1);
    function asp_results_add_custom_image($results) {
    	foreach ( $results as $k => &$r ) {
    		if ( isset($r->taxonomy) ) {
    			$vendor = yith_get_vendor( $r->id, 'vendor' );
    			$im = wp_get_attachment_image_src( 
    				$vendor->avatar, 
    				apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) )  
    			);
    			$r->image = isset($im[0]) ? $im[0] : $r->image;
    		}
    	}
    	
    	return $results;
    }

    If this does not work, then I don’t know what the issue could be.

    Best,
    Ernest Marcinko

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


    #32554
    codigo3net85
    codigo3net85
    Participant

    WOW! working great!!! now i see vendors avatar in ASP results!! THAAAAAANK YOU!!!!!! see attached image.

    Taking advantage of the ticket, one more question. Why if in the settings search i select any category im always getting the same results? no changes, im always getting the same vendors results, check this video please:
    https://www.awesomescreenshot.com/video/3262915?key=8d5b4cdc5c7d23f7a1d11d03dfb83432

    Any advice? Thanks

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

    Because on the screenshot the results are taxonomy terms – and taxonomy terms can not be filtered by taxonomy terms, only post type results can be affected by taxonomy term filters.

    Best,
    Ernest Marcinko

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


    #32582
    codigo3net85
    codigo3net85
    Participant

    Ah! ok! i got it.
    Ernest, thanks a lot for your time and help!

    Thank you!

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.