Given the ID of a product in woocommerce, how can I get its URL?

Say I have the ID of a product in wooCommerce; can I generate its URL somehow? (example /shop/fresh-apples)

Related posts

Leave a Reply

1 comment

  1. Products in WooCommerce are a custom post type, so this should work:

    $url = get_permalink( $product_id );
    

    You can treat that $product_id as a postID (that’s what it is), so you can use it with other normal WP functions, like:

    echo '<a href="'.get_permalink($product_id).'">'.get_the_title($product_id).'</a>';