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

喜欢而已 提交于 2020-01-21 09:14:09

问题


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



来源:https://stackoverflow.com/questions/46486610/how-to-get-woocommerce-product-id-from-its-slug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!