如何从它的 Slug 中获取 WooCommerce 产品 ID? [英] How to Get WooCommerce Product ID from It's Slug?

查看:27
本文介绍了如何从它的 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' );

更好的解释:

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

这篇关于如何从它的 Slug 中获取 WooCommerce 产品 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆