WordPress how to get current url woocommerce product

I am trying to get Woocommerce product permalink by given product name. I know I can get permalink by given product ID like this:
$url = get_permalink( $product_id );

But I can not find any code to get it by product name. I tried this:

$url = get_permalink( 'title' );

Or in the woocommerce template, you can follow the following snippets

global $product;
$produc_id = $product->id;
$url = get_permalink( $product_id );

Also published on Medium.

Leave a Reply

Your email address will not be published. Required fields are marked *