How to add vendor slug to URL in product single views?

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!

Tagged: , , ,

Viewing 2 reply threads
  • Author
    Posts
    • #129107

      Hi there,
      instead of using the default https://site/products/<product slug> structure, I would like to have a permalink structure like https://site/vendor/<vendor slug>/product/<product slug> if possible – is this doable and how?

      Thanks in advance!

    • #129532
      Sushobhan
      Keymaster

      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!

    • #129544
      This reply has been marked as private.
Viewing 2 reply threads
  • You must be logged in to reply to this topic.