在WooCommerce中付款后获取产品ID值(_product_id)的值 [英] Getting the value of the product's id value (_product_id) after the payment in WooCommerce
本文介绍了在WooCommerce中付款后获取产品ID值(_product_id)的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在支付页面(thankyou.php
)上获得_product_id
的值,有人可以帮我这个忙.
I want to get the value of _product_id
on the payout page (thankyou.php
), can somebody help me with this.
我已经附上了我确实需要该值的字段的图片
I have attached an image of the field I need exactly that value
推荐答案
您可以使用
woocommerce_thankyou
挂钩获取产品ID. 谢谢页面
You can use
woocommerce_thankyou
hook to get the product ID's in thankyou page
function wh_getProductIds($order_id)
{
//getting order object
$order = wc_get_order($order_id);
$product_id_arr = [];
//getting all line items
foreach ($order->get_items() as $item)
{
$product = $item->get_product();
$product_id_arr = $product->get_id(); //storing the product ID
//$product_sku = $product->get_sku();
}
//$product_id_arr has all the order's product IDs
//now you can do your stuff here.
}
add_action('woocommerce_thankyou', 'wh_getProductIds', 10, 1);
代码进入活动子主题(或主题)的 functions.php
文件中.或在任何插件php文件中.
代码已经过测试并且可以正常工作. 版本3.x
或更高版本
Code goes in functions.php
file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works. version 3.x
or above
相关:
- Woocommerce在谢谢"页面上获取订单并传递数据javascript代码段
- 两个像素的WooCommerce转化跟踪脚本
- 如何通过订单ID获取订单详细信息
- woocommerce_thankyou钩不起作用
- Woocommerce Get Orders on Thank you page and pass data javascript snippet
- WooCommerce Conversion Tracking Script for two Pixel
- How to Get Order Details by Order ID
- woocommerce_thankyou hook not working
希望这会有所帮助!
这篇关于在WooCommerce中付款后获取产品ID值(_product_id)的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文