Forgot to say that I want to do this beacuse I am migrating from Prestashop to Woocommerce and i want to preserve the same exact URLS for products, not to have broken links all over and to preserve SEO.
I have done some progress and managed to get the custom url I want for the products, exact same ones as in a default Prestashop install. Now my product urls in woocommerce are the same, but problem I have now is that I get 404 error so i’m stuck again … probably will need more hacks…
Here’s the function I have created to match the prestashop links … can someone help to make the urls work now? … thanks.
function append_sku_string( $link, $post ) {
$post_meta = get_post_meta( $post->ID, '_sku', true );
if ( 'product' == get_post_type( $post ) ) {
// $link = $link . '/' .$post_meta;
$parteslink= explode("/", $link);
// https://domain.com/shop/product-category/SKU-product-name.html
$link = $parteslink[2].'/'.$parteslink[3].'/'.$parteslink[4].'/'.$post_meta.'-'.$parteslink[5].'.html';
return $link;
}
}
add_filter( 'post_type_link', 'append_sku_string', 1, 2 );