Get product details by url key in WordPress woocommerce

You simply can use the existing function get_page_by_path() for this, which has a third parameter $post_type you can specify. In your case a post from the custom post type product is what you want.

Basic example:

$product_obj = get_page_by_path( $slug, OBJECT, 'product' );

Leave a Comment