Reputation: 381
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' );
That does not work. Please help.
Upvotes: 27
Views: 94211
Reputation: 507
$product = wc_get_product( $product_id );
$permalink = $product->get_permalink();
Upvotes: 27
Reputation: 81
For URL:
$url = get_permalink($product_id)
For the title:
$name = get_the_title($product_id)
Upvotes: 8
Reputation: 775
This code works for me
$product = get_page_by_title( 'Product Title', OBJECT, 'product' )
echo get_permalink( $product->ID );
Upvotes: 30