Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get product permalink by product name in Woocommerce

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.

like image 548
user3868840 Avatar asked Jul 25 '14 01:07

user3868840


People also ask

How do I get a product link in WooCommerce?

You can use the get_permalink function to get the product URL. You need to pass the product id to get the URL.

How do I get product information by product ID in WooCommerce?

$productId = 164; echo $p_title = get_the_title( $productId ); looking for Short Description, Price, Product Image, Product Url, Product Brand. Or might be loop will be better but that loop should work with product static ID.

How do I get a product slug in WooCommerce?

Go to WooCommerce > Settings > Custom Permalinks. 3. In the “product permalinks” section choose “Product slug alone” or “Product slug with category name” if you want to include category slug into URL.

What is a product permalink?

Permalink is short for “permanent link.” Permalinks are permanent URL structures used to help organize the content of your website (pages, posts, products, etc.) so it can be efficiently navigated, shared, and referenced by users and bots.


2 Answers

This code works for me

$product = get_page_by_title( 'Product Title', OBJECT, 'product' )
echo get_permalink( $product->ID );
like image 83
sabarnix Avatar answered Nov 15 '22 16:11

sabarnix


$product = wc_get_product( $product_id );
$permalink = $product->get_permalink();
like image 28
José Neto Avatar answered Nov 15 '22 16:11

José Neto