Join our new community forum for support & discussion
Join Now‘vendor_view_page’ in the menu
-
AuthorPosts
-
Ragab1805 1 year, 8 months ago
How to add a dynamic link in the menu to redirect the [vendor] to his [listings by vendor] or [vendor_view_page] page?
This would require some custom code snippet, because the URL is different for each user, and not all users are vendors. If you’re familiar with customizations please try using the get_post function to find the vendor ID by the user ID (the user is set as a vendor profile author).
Ragab1805 1 year, 8 months agoI tried to add this snippet to the php file so it can filter the listings page instead of filtering the link in the menu… But it didn’t work properly.
So can you help me find out what went wrong with the snippet?add_filter( 'hivepress/v1/models/listing', function( $model ) { $model['fields']['user']['type']['id'] = ['fields']['vendor']['type']['id'] ; return $model; } );
Ragab1805 1 year, 8 months agoAfter reaching out to my client he refused the filtering solution and insisted to the link in the menu,, so if you can give me a hint about how to do it or where to start cuz I didn’t really understood how can I customize the links in the menu… I will be very grateful.
Thanks in advance ๐Menus are related to the core WordPress features, please check the code snippets here https://wordpress.stackexchange.com/questions/235880/using-filters-to-change-href-of-nav-menu-page-link You can try checking the current user ID, then get the vendor ID and if it’s available get URL via the
get_permalink()
function. Hope this helps.Sergio 1 year, 5 months agoIf youโre familiar with customizations please try using the get_post function to find the vendor ID by the user ID (the user is set as a vendor profile author).
sample code?
You can try this one:
$vendor_id = HivePress\Models\Vendor::query()->filter( [ 'status' => 'publish', 'user' => get_current_user_id(), ] )->get_first_id();
Sergio 1 year, 5 months agoThis code did not work for me (((
used in functions.phpIt should work fine if the current user has a published vendor profile, otherwise the $vendor_id will contain null.
fekedew 1 year, 5 months agotry this. put this code in child theme function.php file
add_filter( 'hivepress/v1/menus/user_account', 'alter_user_account_menu_register1' ); function alter_user_account_menu_register1( $menu ) { global $wpdb; $p_sql = "SELECT <code>post_name</code> FROM wp_posts WHERE <code>post_author</code>=".get_current_user_id()." AND <code>post_type</code>='hp_vendor'"; $row = $wpdb->get_results($p_sql); if(count($row) > 0){ $menu['items']['vender'] = [ 'label' => "Listing page ", 'url' => esc_url( home_url()."/vendor/".$row[0]->post_name ), '_order' => 14, ]; } return $menu; }
natsu 1 year, 4 months agoHi. I tried the code which @fekedew gave above. but the URL still show the default vendor’s link.
Do I only need to put the code to function.php child theme? or do I need to add more code to some where else? What am I missing?
Please help me with this. I think vendor should be able to see how they are displayed on vendor listing page easily by clicking a link.
Thank you in advance!
natsu 1 year, 4 months agoHi everyone.
I came up with a different solution.
Instead of showing a link on Navbar, I managed to put a link within a my account menu.I hope this will help ๐
//Add a link to My listing page within my account menu add_filter( 'hivepress/v1/menus/user_account', function( $menu ) { $menu['items']['custom_item_name'] = [ 'label' => 'My Listings', 'url' => esc_url( home_url()."/vendor/".get_display_name()), '_order' => 123, ]; return $menu; } ); function get_display_name () { $user_data = get_userdata(get_current_user_id()); return $user_data->display_name; }
I don’t know much about PHP I just combined these POSTS.
https://hivepress.io/support/topic/my-account-section/#post-7202
https://hivepress.io/support/topic/change-username-of-vendors/#post-17598Thanks @ihor @Sergio @RooninStark
Thanks for sharing!
-
AuthorPosts
New Reply
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.