WooCommerce Product URL re-writing
I am trying to re-write my WooCommerce product urls to be have the Post ID at the end, like this:
/product/product-name-post-id/
I've used the code from this thread How to rewrite URI of custom post type? which is working, but we have /product/post-id-product-name/.
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/' . $post-post_name . '-' . $post-ID );
} else {
return $link;
}
}
add_action( 'init', 'wpse33551_rewrites_init' );
function wpse33551_rewrites_init(){
add_rewrite_rule(
'product/([0-9]+)?$',
'index.php?post_type=productp=$matches[1]',
'top' );
}
I can't work out how to work the re-write rule in the second function here to get the Post-ID to be at the end?
Topic woocommerce-offtopic Wordpress
Category Web