I want to modify the current permalink structure which Woocommerce assigns to different products which we create. Right now, this is how the URL of a product looks like:
http://example.com/shop/coats-jackets/duis-aliquet-lorem-massa-1/
What I want to do is that, I want to modify the product URL so that it becomes:
http://example.com/coats-jackets/duis-aliquet-lorem-massa-1.html
I tried achieving the above URL structure by adding the following code inside the functions.php file but then whenever I tried to open a product, it gave a Page Not Found 404 error message:
add_filter('post_type_link', 'wpse33551_post_type_link', 1, 3);
function wpse33551_post_type_link( $link, $post = 0 ){
if ( $post->post_type == 'product' ){
return home_url( '%product_cat%/' . $post->post_name . '.html' );
} else {
return $link;
}
}
Basically I want to remove the store name from the URL, i.e. shop, and keep the category name followed by the product name and the product permalink suffix would be '.html'.
Looking forward to a solution. Thanks.