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

1 Answer 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>';
  • How can I change the permalink, so it automatically adds it to the cart?
    – Garconis
    Commented Sep 20, 2017 at 13:09
  • 1
    I found add_to_cart_url() does what I asked above.
    – Garconis
    Commented Sep 20, 2017 at 13:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.