Support » Plugin: WC Marketplace » how to get vendor id from vendor / shop URL

  • Resolved Vivek Athalye

    (@vnathalye)


    Is there any API to get the vendor ID based on the shop URL (/vendor/shop_name/) and vice versa (get shop URL from vendor ID)? I could not find it in WCMp_Vendor class or even wcmp-core-functions.php.

    Note: I’m using v3.0 Beta.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Purnendu Dash

    (@purnendu)

    Hello Vivek,

    Thanks for your query.

    You can get the vendor shop url from vendor id by the following code

    $vendor = get_wcmp_vendor($vendor_id);

    Now you can have the url here – “$vendor->permalink”

    And I am afraid, there is not such dedicated function for the reverse one.

    Hi Purnendu,

    Thanks for your response.

    Based on my understanding I’ve come up with following code to get vendor ID from shop URL:

    $termslug = basename( $shop_url );
    $term = get_term_by('slug', $termslug, 'dc_vendor_shop');
    $vendor_id = get_term_meta($term->term_id, '_vendor_user_id', true);
    // alternatively
    $vendor = get_wcmp_vendor_by_term($term->term_id);
    $vendor_id2 = $vendor ? $vendor->id : false;
    

    Can you please confirm that this will always give me proper vendor ID? (note: $vendor_id is string, but that’s OK)
    And if it’s the right way, then can you please add it as a utility function somewhere, may be in wcmp-core-functions.php?

    Plugin Contributor Purnendu Dash

    (@purnendu)

    Hello @vnathalye,

    Thanks for your contribution, we modified that a bit and here is the function we will be adding in our 3.0

    
    function get_wcmp_vendor_id_by_store_url($store_url) {
       $vendor_id = false;
       $termslug = basename($store_url);
       $term = get_term_by('slug', $termslug, 'dc_vendor_shop');
       if ($term) {
           $vendor = get_wcmp_vendor_by_term($term->term_id);
           $vendor_id = $vendor ? $vendor->id : false;
       }
       return $vendor_id;
    }
    

    Kindly let us know if you have any other suggestion.

    Hey Purnendu,

    That’s gr8. Thanks for accepting this so quickly. 🙂

    You may consider returning the $vendor object instead of $vendor_id (and rename the function accordingly).

    1. So that it matches the way we get shop URL from vendor ID: first get the vendor object and then access required property. (as you posted earlier)
    2. Currently its fulfilling my specific need but when you return vendor object, it will become more generic and allow accessing other properties of vendor object more easily. That might be helpful to other users.

    I don’t think I need to tell you this, but just in case if you have missed it, you may want to remove hardcoded dc_vendor_shop and use $WCMp->taxonomy->taxonomy_name :).
    I used the hardcoded value just because I wanted to get confirmation if my approach is right or not, but yes, I should have used that property myself 😉

    Kindly let us know if you have any other suggestion.

    I’ve already sent few mails to ‘Plugins DC’ mail ID. To be specific 6 emails with couple suggestions and 15/16 issues (UI + functionality related). But I have got response only once. (I was expecting more responses like issue accepted/rejected; clarification / more info needed; etc.) If someone can take a look at those mails and respond, that will boost my confidence that my mails are being read and acted upon. 🙂

    Btw is there any ETA for v3.0?

    Plugin Author WC Marketplace

    (@dualcube)

    Our team has added the changes and filter that you habe recommended here and over the email.

    Thanks again for taking your time and helping us with your feedback.

    Regarding the official update, we are hoping to release this either in this or next week for sure.

    Wow. Happy to hear that. Eagerly waiting for official release.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to get vendor id from vendor / shop URL’ is closed to new replies.