Use of users custom fields in a product search

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Use of users custom fields in a product search

This topic contains 19 replies, has 2 voices, and was last updated by T0mX06 T0mX06 3 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #27089
    T0mX06
    T0mX06
    Participant

    Hi,

    I’m trying to use ASP with WCFM MarketPlace. Everyhing went fine but there is one thing i could not acheive :
    I want to use the custom fields create by WCFM MarketPlace in users’ profils (like store name, store policy …) in the products search list (for example, if I search for a product A, the name of the product is displayed in the search list, but also in its description the store name). I could not do that I think because these custom fields like store name are in the users’ customs fields and not in the product one. So my question is, may i ‘link’ or load all the users metadata in function.php to make them available in the product search ?

    #27093
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I’m afraid that is not possible. Using a custom code will not help, as there is no direct connection between user meta and posts. This would require direct modifications to the core search code to make it work – but even then it might not work correctly.

    Best,
    Ernest Marcinko

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


    #27099
    T0mX06
    T0mX06
    Participant

    Hi,

    Thanks for your answer. Do you think there is a way to sync metadata between users ones and products ones ?

    #27101
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Could be possible. Perhaps an import/export plugin might be able to do that. Although if you have a lot of products (thousands), I would highly discourage using custom fields – as it would be repetitive, taking up a lot from the post meta table. Using taxonomy terms (like categories) could be a better idea – as the same tags can be assigned to multiple posts.

    Do you happen to know the names of these user meta fields? If these are all user meta, then using the index table engine there might be a way to use a custom code – to index these meta data along with product descriptions (sort of).

    Best,
    Ernest Marcinko

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


    #27105
    T0mX06
    T0mX06
    Participant

    Hi,

    Yes they are all users meta. You will find below all the customs fields I would like to use in the product search list.
    If you could acheive this via a custom code and the index table this will be amazing !

    Thanks for everything

    _store_description
    store_name
    wcfm_vendor_store_hours

    ‘store_email’
    ‘phone’
    ‘payment’
    ‘wcfm_store_hours’
    ‘wcfm_shipping_policy’
    ‘wcfm_vacation_mode’
    ‘store_location’
    wcfmmp_store_name

    #27109
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Okay, if these are indeed the author metadata, then this custom code may do the trick:

    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_post_content_before_tokenize', 'vendor_asp_post_content_before_tokenize', 10, 2);
    function vendor_asp_post_content_before_tokenize($content, $the_post) {
    	$meta_fields = array(
    		'_store_description',
    		'store_name',
    		'wcfm_vendor_store_hours',
    		'store_email',
    		'phone',
    		'payment',
    		'wcfm_store_hours',
    		'wcfm_shipping_policy',
    		'wcfm_vacation_mode',
    		'store_location',
    		'wcfmmp_store_name'
    	);
    	foreach ( $meta_fields as $field ) {
    		$s = get_user_meta( $the_post->post_author, $field, true );
    		if ( !empty($s) ) {
    			$content .= ' ' . $s;
    		}
    	}
        return $content;
    }

    After that, you will have to re-create the index table. You will find all the information in this documentation.

    Best,
    Ernest Marcinko

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


    #27111
    T0mX06
    T0mX06
    Participant

    Ok,

    First of all thanks for everything. Really !
    I’ve done the changes in function.php. I’ve switched the search engine from regular to index one. Added a {wcfmmp_store_name} and a {store_name} just in case but both are filled with stores names informations. The results don’t display the store name in the results.
    Perheaps you’ll need my creditentials to log in my admin and see my function.php in my FTP ?

    #27112
    T0mX06
    T0mX06
    Participant
    You cannot access this content.
    #27122
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, I’m sorry, I missunderstood your query.

    You wanted to display the store data in the results content or title fields, and not search by that data. Since you added back-end access, I made another quick code to make it work, and already included in the functions.php file.

    Now, use the store user meta fields in the advanced title and content fields like this: ||store_name||
    ..the new code will recognize that: https://i.imgur.com/UnFp2Ix.png

    For future reference, I added this code there:

    // Vendor user meta fields to advanced title and content
    add_filter('asp_results', 'vendor_asp_post_content_user_meta', 10, 1);
    function vendor_asp_post_content_user_meta($results) {
    	$meta_fields = array(
    		'_store_description',
    		'store_name',
    		'phone',
    		'store_email',
    		'wcfm_vendor_store_hours',
    		'_wcfm_email_verified',
    		'_wcfm_email_verified_for',
    		'wcemailverified',
    		'_wcfm_billing_phone',
    		'payment',
    		'wcfm_store_hours',
    		'wcfm_shipping_policy',
    		'wcfm_vacation_mode',
    		'_wcfm_store_location',
    		'wcfmmp_store_name'
    	);
    	foreach ( $results as &$r ) {
    		foreach ( $meta_fields as $field ) {
    			if ( strpos($r->content, '||' . $field . '||') !== false ) {
    				$s = get_user_meta( get_post_field( 'post_author', $r->id ), $field, true );
    				if ( !empty($s) ) {
    					$r->content = str_replace('||' . $field . '||', $s, $r->content);
    				} else {
    					$r->content = str_replace('||' . $field . '||', '', $r->content);
    				}
    			}
    		}
    	}
        return $results;
    }
    Best,
    Ernest Marcinko

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


    #27131
    T0mX06
    T0mX06
    Participant

    Thank you so much ! That’s perfect. 5 stars customer support

    Will the changes made will still work with the next updates of ASP ?

    Last question, may I have to keep the index search engine or I could use the normal one ? Ok i’ve tested and it works with the classic search engine 😉

    • This reply was modified 3 years, 11 months ago by T0mX06 T0mX06.
    #27132
    T0mX06
    T0mX06
    Participant

    oh, and do you think that I could use the store logos instead of the default avatar ?
    I think its store-avatar that is used or gravatar that is listed in the user metadas

    • This reply was modified 3 years, 11 months ago by T0mX06 T0mX06.
    #27137
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you very much 🙂

    Yes, it could be doable, depends on how exactly is that avater stored. I tried to look for user meta with the avatars, but there are no matches for “avatar”, “logo”, “image” – so I don’t know where those could be stored. Let me know if you find out, and I will suggest another custom code to fix that.

    Best,
    Ernest Marcinko

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


    #27141
    T0mX06
    T0mX06
    Participant

    The only thing i’ve found for now is that. Like the image is associated with a gravatar number.
    wcfmmp_profile_settings
    array (
    0 =>
    array (
    ‘user_name’ => ‘Boutique Demo 3’,
    ‘user_email’ => ’[email protected]’,
    ‘first_name’ => ‘Boutique Démo 3 Prénom’,
    ‘last_name’ => ‘Boutique Démo 3 Nom’,
    ‘store_name’ => ‘Boutique Démo 3’,
    ‘store_slug’ => ’boutique-demo-3′,
    ‘store_email’ => ’[email protected]’,
    ‘phone’ => ‘0490000000’,
    ‘vendor_id’ => ‘99999’,
    ‘gravatar’ => ‘254’,
    ‘banner_type’ => ‘single_img’,
    ‘banner’ => ”,
    ‘banner_video’ => ”,
    ‘banner_slider’ =>
    array (
    0 =>
    array (
    ‘image’ => ”,
    ‘link’ => ”,
    ),
    ),

    #27145
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Well, try this custom code then:

    add_filter( 'asp_results', 'asp_custom_images_gr', 10, 4 );
    function asp_custom_images_gr( $results, $id, $is_ajax, $args ) {
    	foreach ($results as $k=>&$r) {
    		if ( $r->content_type == 'user' ) {
    			$s = get_user_meta( $r->id, 'wcfmmp_profile_settings', true );
    			if ( isset($s['gravatar']) ) {
    				$r->image = get_avatar_url($s['gravatar']);
    			}
    		}
    	}
    
    	return $results;
    }

    I suspect that this may not work though, usually gravatars are handled by WordPress internally, and the search should already return them when they are enabled – but it’s worth a try.

    Best,
    Ernest Marcinko

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


    #27149
    T0mX06
    T0mX06
    Participant

    Tried and not working :(. Like you say it worth the try.
    I’ve found this perheaps it could help ?
    https://wclovers.com/forums/topic/display-the-store-logo-and-the-avatar-of-the-vendor/

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

The topic ‘Use of users custom fields in a product search’ is closed to new replies.