Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor titodevera

    (@titodevera)

    Hi play33.

    Removing /product/ from the URLs is not advisable due to the way WordPress resolves its URLs. That can lead to a number of problems with performance and duplicate URLs.

    More info here: Removing /product/ from the URLs

    As an alternative you can add the brand to the products urls without removing the base. The code below does the trick:

    
    add_filter( 'woocommerce_register_post_type_product', 'custom_pwb_product_post_type_rewrite' );
    function custom_pwb_product_post_type_rewrite($data){
      $data['rewrite']['slug']       = $data['rewrite']['slug'] . '/%pwb-brand%';
      $data['rewrite']['with_front'] = false;
      return $data;
    }
    
    add_filter( 'post_type_link', 'custom_pwb_add_brand_name_in_url', 10, 2 );
    function custom_pwb_add_brand_name_in_url( $permalink, $post ) {
      if( $post->post_type == 'product' ) {
        $term   = 'product';
        $brands = wp_get_post_terms( $post->ID, 'pwb-brand' );
        if( ! empty( $brands ) && ! is_wp_error( $brands ) ) $term = current( $brands )->slug;
        $permalink = str_replace( '%pwb-brand%', $term, $permalink );
      }
      return $permalink;
    }
    

    Your urls can now looks like: https://www.bcgel.co.uk/shop/moroccanoil/moroccanoil-treatment-light-100ml/ for example (assuming that ‘shop’ is the base)

    ??

    Hey there,
    How would I add the brand to the Woocommerce breadcrumbs? so instead of Home / Products / E-Liquid / Wild Apple, I would like to replace the category with brand… to:
    Home / Products / Air Factory / Wild Apple.

    Thanks in advance
    Dino

    • This reply was modified 5 years, 5 months ago by Dino.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Brand name in URL’ is closed to new replies.