0

I have some products with Color attribute. how can I have something like this:

http://example.com/shop/category-name/product-title-color/

What should I do make this kind of permalink in WooCommerce.

0

You can do like this, to append QUERY to permalinks (not base url):

add_filter( 'post_type_link', 'my_append_query_string', 10, 4 ); 
function my_append_query_string( $permalink, $post, $leavename, $sample ) { 
    if ( $post->post_type == 'shop' )  {
        if (get_option('permalink_structure')){ 
            $permalink = AddStringToUrl($permalink,'color=red');
        }
    }
    return $permalink;
}

function AddStringToUrl($current_url, $string) {
    return $current_url  
           . ( stripos($current_url, '?') === false ? '?' : '&' ) 
           . $string; 
}
| improve this answer | |
  • Thank you Tazo, but I don't want to do this way and line 4 of your code should be if ( $post->post_type == 'product' ) – silvercover Nov 17 '16 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.