Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › How to add vendor slug to URL in product single views?
- This topic has 2 replies, 2 voices, and was last updated 4 years, 6 months ago by inQrt Mobile Solutions.
- AuthorPosts
- May 10, 2020 at 1:43 pm #129107inQrt Mobile SolutionsParticipant
Hi there,
instead of using the defaulthttps://site/products/<product slug>
structure, I would like to have a permalink structure likehttps://site/vendor/<vendor slug>/product/<product slug>
if possible – is this doable and how?Thanks in advance!
- May 11, 2020 at 3:47 pm #129532SushobhanKeymaster
Hi,
Thanks for getting in touch with us!
Step 1: Use the following snippet for this-add_filter( 'post_type_link', function( $post_link, $post, $leavename, $sample ) { if ( 'product' != get_post_type( $post ) ) return $post_link; $authordata = get_userdata( $post->post_author ); $author = $authordata->user_nicename; $post_link = str_replace( '%vendor_name%', $author, $post_link ); return $post_link; }, 50, 4 ); add_action( 'init', function() { add_rewrite_rule( 'vendor/(.?.+?)/product/?(.?.+?)/?$', 'index.php?author_name=$matches[1]&post_type=product&product=$matches[2]', 'top' ); });
Add this code to your child theme’s functions.php
In case you do not have child theme then add code using this plugin – https://wordpress.org/plugins/code-snippets/
Step 2: Go to wp-admin >> Settings >> Permalinks, under Product permalinks section choose Custom base and input this- /vendor/%vendor_name%/product/Let me know how this goes.
Thanks! - May 11, 2020 at 4:03 pm #129544inQrt Mobile SolutionsParticipantThis reply has been marked as private.
- AuthorPosts
- You must be logged in to reply to this topic.