Woocommerce:如何从 id 中获取产品 slug? [英] Woocommerce: How do I get the product slug from the id?

查看:30
本文介绍了Woocommerce:如何从 id 中获取产品 slug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在购物车中有可用的产品 ID,我需要检索 slug.我该怎么做?

I currently have the product id available in the cart and I need to retrieve the slug. How can I do this?

推荐答案

您可以使用 get_post

$product = get_post( 27 ); 
$slug = $product->post_name;
echo $slug;

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

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