Add Product Attribute to Permalink in WooCommerce

To add QUERY to permalinks you can do like this (not the 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; 
}

Leave a Comment