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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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