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.
You can use the get_permalink function to get the product URL. You need to pass the product id to get the URL.
$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.
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.
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.
This code works for me
$product = get_page_by_title( 'Product Title', OBJECT, 'product' )
echo get_permalink( $product->ID );
$product = wc_get_product( $product_id );
$permalink = $product->get_permalink();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With