Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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>';
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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