如何从它的 Slug 中获取 WooCommerce 产品 ID? [英] How to Get WooCommerce Product ID from It's Slug?
本文介绍了如何从它的 Slug 中获取 WooCommerce 产品 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以仅通过知道 slug
来获取 WooCommerce 产品的 ID
?我需要获取产品页面外的产品价格.
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.
推荐答案
使用现有函数get_page_by_path();
use the existing function get_page_by_path();
$product_obj = get_page_by_path( $slug, OBJECT, 'product' );
更好的解释:
这篇关于如何从它的 Slug 中获取 WooCommerce 产品 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文