Is there a shortcode or variable to access the "My Store" value?

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

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: 

Viewing 10 reply threads
  • Author
    Posts
    • #89758
      Lisa DeLuca
      Participant

      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.

    • #90814

      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.

    • #90825
      kaloomee
      Participant

      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

      • #91025

        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.

    • #91864
      kaloomee
      Participant

      As a sub-menu link to – Attached

      Attachments:
      You must be logged in to view attached files.
      • #91961

        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.

    • #91980
      kaloomee
      Participant

      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 you

      Attachments:
      You must be logged in to view attached files.
    • #91982
      kaloomee
      Participant
      This reply has been marked as private.
    • #91989

      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.

    • #92044
      kaloomee
      Participant

      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 location

      Thank you

      Attachments:
      You must be logged in to view attached files.
    • #92180

      Hi,

      You are always welcome 🙂
      1 – Open link to ‘My Shopfront’ in new tab

      Add 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.
    • #92194
      kaloomee
      Participant

      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 1

      function 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.
      • #92252

        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.php

        add_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.

    • #92298
      kaloomee
      Participant

      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 🙂

Viewing 10 reply threads
  • The topic ‘Is there a shortcode or variable to access the "My Store" value?’ is closed to new replies.