It isn’t working because you’ve mixed up returning values and echoing values
updateToPerfectURLs(the_permalink());
Here updateToPerfectURLs
returns its value, but you’ve not printed it out. Try echo/etc
Your second problem is the opposite, the_permalink()
doesn’t return the permalink, it echos it out. So before you’ve even gotten into the function the permalink is printed out. Use get_permalink()
instead,.
Finally, don’t pass a function call directly into another, it makes things harder to read and debug
Giving you:
$permalink = get_permalink();
echo updateToPerfectURLs( $permalink );
Of course there is probably a better way to do this using the various filters without hardcoding product names in your function. That would be a new question you should ask! I imagine it would be useful to many people. Perhaps a rewrite endpoint would work too