How to Get WooCommerce Product ID from It's Slug?

testimonial picture testimonial · Sep 29, 2017 · Viewed 8.8k times · Source

Is it possible to get an ID of a WooCommerce product only by knowing it's slug? I need to fetch the product's price outside the product's page.

Answer

newbie picture newbie · Sep 29, 2017

use the existing function get_page_by_path();

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

better explanation :

https://wordpress.stackexchange.com/questions/206886/get-product-details-by-url-key-in-wordpress-woocommerce