Php WooCommerce-按产品id获取产品描述
如何使用产品ID获取产品描述或产品对象Php WooCommerce-按产品id获取产品描述,php,wordpress,woocommerce,product,orders,Php,Wordpress,Woocommerce,Product,Orders,如何使用产品ID获取产品描述或产品对象 $order = new WC_Order($order_id); foreach ($order->get_items() as $item) { $product_description = get_the_product_description($item['product_id']); // is there any method can I use to fetch the product description? } 上面的代
$order = new WC_Order($order_id);
foreach ($order->get_items() as $item) {
$product_description = get_the_product_description($item['product_id']); // is there any method can I use to fetch the product description?
}
上面的代码扩展了WC\u类支付网关
任何帮助都将不胜感激 如果您使用的是WooCommerce
3.0
或更高版本,则可以使用以下代码获取说明
$order = new WC_Order($order_id);
foreach ($order->get_items() as $item)
{
$product_description = get_post($item['product_id'])->post_content; // I used wordpress built-in functions to get the product object
}
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item) {
$product_id = $item['product_id'];
$product_details = $product->get_data();
$product_full_description = $product_details['description'];
$product_short_description = $product_details['short_description'];
}
备用方式(推荐)
希望这有帮助 我认为,缺少一行,比如$product=新的WC\U产品($product\U id);我还建议使用特定的方法来确保钩子被执行:$product\u full\u description=$product->get\u description()$product_short_description=$product->get_short_description();提示:如果你的描述写在帖子内容中,请使用文森特的答案;如果您的描述写在WooCommerce的产品描述字段中,请使用Raunak的答案。
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item) {
$product_id = $item['product_id'];
$product_instance = wc_get_product($product_id);
$product_full_description = $product_instance->get_description();
$product_short_description = $product_instance->get_short_description();
}