Add a product attribute to permalink in WooCommerce

admin2025-01-08  8

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

color/

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

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.

Share Improve this question asked Nov 17, 2016 at 7:47 silvercoversilvercover 131 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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; 
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270885a1463.html

最新回复(0)