Hi,
I use this code to create a shortcode in order to get the current user’s last name
// [current_user_display_last_name]
function display_current_user_last_name () {
$user = wp_get_current_user();
$last_name= $user->last_name;
return $user->last_name;
}
add_shortcode(‘current_user_last_name’, ‘display_current_user_last_name’);
is it possible to get the value of a specific attibute for the current vendor?
yevhen
November 30, 2023, 4:40am
3
It is possible to get vendor attribute value in this way
$vendor = \HivePress\Models\Vendor::query()->filter(['user' => get_current_user_id()])->get_first();
$vendor->get_put_here_attribute_field_name();
Thank you yevhen, it works perfectly for text attributes.
Is it possible to get the same for “select” attributes (multi option)s) ?
If I use the same code, it returns “Array” for select fields…
Thanks
Christophe:
Is it possible to get the same for “select” attributes (multi option)s) ?
If I use the same code, it returns “Array” for select fields…
Do you have any idea to solve that issue?
ihor
December 6, 2023, 12:46pm
8
I’m sorry for the delay. Yes, for selectable attributes there’s an array of selected options, you can iterate over them and get their label if needed via the get_name
method. You can also display comma-separated labels this way:
$labels=$vendor->display_attribute_name_here();
Hope this helps.
Thanks ihor, it works perfectly
system
Closed
January 5, 2024, 12:58pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.