The question is simple, if I know the SKU of my product and nothing else, how can I retrieve the url/permalink to that item?
This is commonly useful for third party integration.
The question is simple, if I know the SKU of my product and nothing else, how can I retrieve the url/permalink to that item?
This is commonly useful for third party integration.
You can use dedicated function wc_get_product_id_by_sku( $sku )
where $sku
argument is the SKU of your product.
It will return the product ID.
Reference: Function wc_get_product_id_by_sku
Then to get the permalink:
$sku = 'Gh2563'; // SKU example to be replaced by the real SKU of the product $product_id = wc_get_product_id_by_sku( $sku ); $link = get_permalink( $product_id );
hope this help.
Thanks