Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Is there a shortcode or variable to access the "My Store" value?
Tagged: shortcode
- This topic has 13 replies, 3 voices, and was last updated 5 years ago by kaloomee.
- AuthorPosts
- October 31, 2019 at 2:12 am #89758Lisa DeLucaParticipant
I’d like to add a link to my WordPress Menu to the “My Store” location. ex. http://example.com/browse/mystore. But I can’t figure out how to get that dynamic variable as it’ll be different for each logged in user.
- November 5, 2019 at 5:59 pm #90814Sarmistha ChakrabortyMember
Hello,
Try the below code,
add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 ); function your_custom_menu_item ( $items, $args ) { if(is_user_logged_in()) { $current_user_id = get_current_user_id(); //$args->theme_location == <menu location> if ($args->theme_location == 'primary' && wcfm_is_vendor($current_user_id)) { $store_url = wcfmmp_get_store_url( $current_user_id ); $items .= '<li><a href="'.$store_url.'">'.__('My Store','wc-multivendor-marketplace').'</a></li>'; } } return $items; }
Thanks.
- November 5, 2019 at 6:20 pm #90825kaloomeeParticipant
Thank you for posting suggested code
I have added the code as a snippet,
And how would I then add as a menu link?
Thank you- November 6, 2019 at 11:17 am #91025Sarmistha ChakrabortyMember
Hello,
The above code add a menu “My store” for vendor in main menu location.
Please send us the screenshot where you want to add menu link in your site.Thanks.
- November 12, 2019 at 12:13 am #91864kaloomeeParticipant
As a sub-menu link to – Attached
Attachments:
You must be logged in to view attached files.- November 12, 2019 at 2:52 pm #91961Sarmistha ChakrabortyMember
Hello,
We presume that, you have added the “My Dashboard” menu using above code. And you want add a sub-menu link(“My store”) under the menu “My Dashboard”.
Then add the below code in your activated theme’s functions.php instead of previously added code.add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 ); function your_custom_menu_item ( $items, $args ) { if(is_user_logged_in()) { $current_user_id = get_current_user_id(); if ($args->theme_location == 'primary' && wcfm_is_vendor($current_user_id)) { $store_url = wcfmmp_get_store_url( $current_user_id ); $items .= '<li><a href="#">'.__('My Dashboard','wc-multivendor-marketplace').'</a> <ul class="sub-menu"><li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="'.$store_url.'">'.__('My Store','wc-multivendor-marketplace').'</a></li></ul></li>'; } } return $items; }
Thanks.
- November 12, 2019 at 4:25 pm #91980kaloomeeParticipant
Hi
The ‘My dashboard link is a custom url #I have now added screenshot of dropdown where I would like the ‘My STore’ menu link to appear
I have tried adding the code as a snippet but nothing shows
Any further help appreciated
Thank youAttachments:
You must be logged in to view attached files. - November 12, 2019 at 4:26 pm #91982kaloomeeParticipantThis reply has been marked as private.
- November 12, 2019 at 5:25 pm #91989Sarmistha ChakrabortyMember
Hi,
Thanks for the details. Now we understand your requirement. Please try this code,
function dynamic_submenu_wcfmstore_link( $items, $args ) { $theme_location = 'primary';// Theme Location slug $existing_menu_item_db_id = 149; // parent menu item database id $new_menu_item_db_id = 99999; // unique id number $label = __('My Store','wc-multivendor-marketplace'); if ( $theme_location !== $args->theme_location ) { return $items; } if ( is_user_logged_in() ) { $current_user_id = get_current_user_id(); // only if user is logged-in, do sub-menu link if(wcfm_is_vendor($current_user_id)) { $url = wcfmmp_get_store_url( $current_user_id ); $item = array( 'title' => $label, 'menu_item_parent' => $existing_menu_item_db_id, 'ID' => 'custom-my-store', 'db_id' => $new_menu_item_db_id, 'url' => $url, // 'classes' => array( 'custom-menu-item' )// optionally add custom CSS class ); $new_items[] = (object) $item; // insert item $location = 3; // insert at 3rd place array_splice( $items, $location, 0, $new_items ); } } return $items; } add_filter( 'wp_nav_menu_objects', 'dynamic_submenu_wcfmstore_link', 10, 2 );
Hope that will work. (ref : https://isabelcastillo.com/dynamically-sub-menu-item-wp_nav_menu)
Otherwise please share us your site admin access here :https://wclovers.com/woocommerce-multivendor-customization/ with the topic link.Thanks.
- November 12, 2019 at 11:10 pm #92044kaloomeeParticipant
Most excellent, Thank you – Works great
Now…. Screenshot attached for reference
Could you please teach me how to :-
1 – Open link to ‘My Shopfront’ in new tab
2 – Add icon to menu link
3 – Position menu link order – currently shows in top/1st but I would like it 2nd down
trying to learn, I have looked at code which has ‘$location = 3; // insert at 3rd place’ – Tried editing this but still shows in 1st locationThank you
Attachments:
You must be logged in to view attached files. - November 13, 2019 at 7:26 pm #92180Sarmistha ChakrabortyMember
Hi,
You are always welcome 🙂
1 – Open link to ‘My Shopfront’ in new tabAdd this script to your js file,
$('#menu-item-custom-my-store a').each(function() { $(this).attr("target","_blank"); });
2 – Add icon to menu link
>> Change $label with,
$label = '<i class="fa fa-desktop" aria-hidden="true"></i>'.__('My Store','wc-multivendor-marketplace');
3 – Position menu link order – currently shows in top/1st but I would like it 2nd down
>>change $location with,
$location = 8;// menu item number (PFA for this case 8th position)Let me know if there’s anything else we can help you with.
Can we ask for a favor? Would you mind taking a few minutes to review our plugin at https://wordpress.org/support/plugin/wc-multivendor-marketplace/reviews/ and let others know about your 5 Star experience with WCFM Marketplace. Also, follow us on Twitter https://twitter.com/wcfmmp for more exciting news, important updates, and irresistible offers.Attachments:
You must be logged in to view attached files. - November 13, 2019 at 10:50 pm #92194kaloomeeParticipant
Hello,
Wahay, Wonderful 🙂
A couple of issues though
1 – I have added this js code to the themes (Rehub-revendor) general options > ‘Js code for footer’. But menu link still opens in same tab
2 – Icon now displays, Thanks
3 – I have edited ‘$location’ as suggested but menu item still shows in location 1function dynamic_submenu_wcfmstore_link( $items, $args ) { $theme_location = 'primary-menu';// Theme Location slug $existing_menu_item_db_id = 781; // parent menu item database id $new_menu_item_db_id = 96969; // unique id number $label = '<i class="fa fa-store" aria-hidden="true"></i>'.__('My Shopfront','wc-multivendor-marketplace'); if ( $theme_location !== $args->theme_location ) { return $items; } if ( is_user_logged_in() ) { $current_user_id = get_current_user_id(); // only if user is logged-in, do sub-menu link if(wcfm_is_vendor($current_user_id)) { $url = wcfmmp_get_store_url( $current_user_id ); $item = array( 'title' => $label, 'menu_item_parent' => $existing_menu_item_db_id, 'ID' => 'custom-my-store', 'db_id' => $new_menu_item_db_id, 'url' => $url, // 'classes' => array( 'custom-menu-item' )// optionally add custom CSS class ); $new_items[] = (object) $item; // insert item $location = 8;// menu item number (PFA for this case 8th position) array_splice( $items, $location, 0, $new_items ); } } return $items; } add_filter( 'wp_nav_menu_objects', 'dynamic_submenu_wcfmstore_link', 10, 2 );
Attachments:
You must be logged in to view attached files.- November 14, 2019 at 12:46 pm #92252Sarmistha ChakrabortyMember
Hello,
1 – I have added this js code to the themes (Rehub-revendor) general options > ‘Js code for footer’. But menu link still opens in same tab
>> What I see it was placed in wrong place. Add this script to your theme’s functions.phpadd_action('wp_footer',function() { ?> <script type="text/javascript"> jQuery('#menu-item-custom-my-store a').each(function() { jQuery(this).attr("target","_blank"); }); </script> <?php });
3 – I have edited ‘$location’ as suggested but menu item still shows in location 1
>>Your $location will be 21. It’s the position of the menu where you want to place it.
$location = 21;Thanks.
- November 14, 2019 at 5:03 pm #92298kaloomeeParticipant
Wow, Such great support – Thank you
As a non-coder this support is amazing
All now working as requested
Thank you very, very much
I am now following on Twitter and written a review on WordPress plugins page
Really is much appreciated
My round at the bar next we meet 🙂
- AuthorPosts
- The topic ‘Is there a shortcode or variable to access the "My Store" value?’ is closed to new replies.