I think that you need only to change the way get_permalink
create url for the cpt, ignoring the parent.
You can do it adding a filter to 'post_type_link'
hook and then regenerate the permalink for the product cpt in the same way is done in core, just ignoring the parent:
add_filter('post_type_link', 'reset_light_link', 999, 3);
function reset_light_link( $post_link, $post, $leavename ) {
if ( $post->post_type != 'light' || in_array($post->post_status, array('draft','pending','auto-draft')) ) return $post_link;
global $wp_rewrite;
$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
if ( ! $leavename ) $post_link = str_replace("%$post->post_type%", $post->post_name, $post_link);
return home_url( user_trailingslashit($post_link) );
}
The code for reset_light_link
function is just a modded version of get_post_permalink
, the function used in core to generate the permalink (and that fires the 'post_type_link'
hook) when get_permalink
is called for a cpt.
Here the code for that function.