Support » Plugin: Dokan - Best WooCommerce Multivendor Marketplace Solution - Build Your Own Amazon, eBay, Etsy » Permalinks: Need to include store name in product permalink or slug looks bad

  • Resolved phirefly

    (@phirefly)


    Problem:
    Many vendors sell products with similar / same names. For multi-vendor this is bad because there is currently no store-name in slug and results in lots of bad product urls…

    Currently Dokan does this:
    /product/product-name/
    /product/product-name-2/
    /product/product-name-3/

    We want Dokan to do this (or something similar whereby the store-name is included):

    /store-A/product/product-name/
    /store-B/product/product-name/
    /store-c/product/product-name/

    Can you advise?

    We are also interested in ANY solution that will prevent products being created with a “_2”, “-3” etc slug….even if that solution does not include the “store-name”.

    • This topic was modified 4 months, 3 weeks ago by phirefly. Reason: Added the "also interested in ANY solution..."
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Rashed Ripon

    (@rur165)

    Hello @phirefly ,

    Thanks for the suggestion. The majority of our Dokan users love the default way to see the product without a store name associated with this. For your case, you need to go for custom development to get such results.

    The product URL and the whole product creation in Dokan is handled through default WooCommerce operation. So, if you can modify the WooCommerce’s default nature to make custom permalink then it will work for Dokan as well. If you just need to know a way to pull the store-url then I can share the reference code from Dokan Lite. But first I will recommend to check if this is possible in WooCommerce to change default nature of product slug.

    Thank you.

    Hi Rashed,

    thanks for the quick reply. So in https://wedevs.com/docs/dokan/getting-started/basic-configuration/, when it says;
    “Dokan requires the system URL to be configured in a specific format…” this “specific format” is not specific to Dokan? It is actually referring to Woocommerce?

    Can you confirm or correct the above?

    I just wanted to be sure there is nothing Dokan-specific regarding permalinks/taxonomy etc.

    Also can you also let me know what the permalink “tag” is for Vendor store name (eg. like; /%postname%/, /%category%/ used in /wp-admin/options-permalink.php) and any other useful information we should consider?

    Thanks

    NOTE: We cannot use the Vendor username %author% because this is generally not the same as the store-name.

    The users are only interested in the store-name. (we have hidden/removed the vendor-name everywhere on our marketplace because of this).

    We only use the store-name.

    Thanks

    • This reply was modified 4 months, 3 weeks ago by phirefly. Reason: clarifying

    Hi Rashed,

    based on Woocommerce, we now have product permalinks working the way we want on on the front end (ie. including /store-name/) however the Vendor dashboard is not loading – only the page title loads, not the content.

    Is there something else about Dokan permalink structure we need to know? Something outside of Woocommerce?

    Thanks

    Plugin Support Rashed Ripon

    (@rur165)

    Hello @phirefly ,

    Dokan need two permalink structure to be exactly like this –
    common settings – /%postname%/
    Product permalinks – /product/ (I tested with a different structure and it worked)

    Dokan store name does not have a value like %store-name%. It is actually handled differently. Here is a way to call that –

    $vendor = dokan()->vendor->get( $seller ); and then get the store name –
    $vendor->get_shop_name()

    You have to programmatically push the store URL in the product permalink in your solution.

    Thank you.

    For anybody reading this, you cannot simply update the Woocommerce permalink settings. If you do this, the product urls will still work…however your Dokan dashboards will break.

    I have tested and can recommend Permalink Manager Pro (https://permalinkmanager.pro). They have developed a solution for Dokan and will be making it available in the next release later this month. In meantime, the developer shared the functions code (that will be included in the next release) and I can confirm it works brilliantly 🙂

    To whom it may concern:

    I received a new request from another user asking how to include the store name in the product permalinks 🙂

    The solution is not so difficult. Before I add this functionality to Permalink Manager, you can use this simple code snippet instead:

    
    /**
     * Use %store% in Products' permastructure settings
     */
    function pm_dokan_store_field($default_uri, $native_slug, $post, $slug, $native_uri) {
        // Do not affect native URIs
        if($native_uri == true || empty($post->post_type) || $post->post_type !== 'product') { return $default_uri; }
     
        if(strpos($default_uri, '%store%') !== false) {
            $store_name = get_user_meta($post->post_author, 'dokan_store_name', true);
            $default_uri = str_replace('%store%', sanitize_title($store_name), $default_uri);
        }
     
        return $default_uri;
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_dokan_store_field', 3, 5);
    

    Please paste it to functions.php file in your (child) theme directory. Then, you will be able to use %store% permastructure tag for Products.

    Please note that by default, the store name will be added only to the new products. You can also include it in existing URLs using “Regenerate/reset” tool.

    In the below article you can find more instructions on how exactly this tag can be used for permastructure settings:
    https://permalinkmanager.pro/docs/basics/bulk-edit-wordpress-permalinks/

    Best regards,
    Maciej

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.