wordpress Woocommerce支付网关-当我有订单ID时,我无法获得产品ID

zujrkrfu  于 2023-03-22  发布在  WordPress
关注(0)|答案(1)|浏览(170)

Woocommerce支付网关插件:当我有订单ID时,我无法获得产品ID。
在付款页面上,购物车和结账后,我有订单ID,在本例中为5648。我需要获得订单的单个产品ID,并期望以下代码可以工作,但我得到一个错误“致命错误:未捕获的错误:调用成员函数get_items()on int”-是因为我在循环之外吗?:

$orderid = $order->get_id();
        foreach( $orderid->get_items() as $order_item ) {
            $product = $order_item->get_product();
            $product_id = $product->get_id();
            echo $product_id;
        }

完整的错误消息供参考:
“致命错误:未捕获的错误:在/home/customer/www/ www.example.com中调用成员函数get_items()onxyz.com/public_html/site/wp-content/plugins/woocommerce-gateway-nab-dp/woocommerce-nab-dp.php:946堆栈跟踪:Copyright © 2018 - 2019 www.xyz.com/public_html/site/wp-includes/class-wp-hook.php All rights reserved.Copyright © 2018 - 2019 www.xyz.com/public_html/site/wp-includes/class-wp-hook.php All rights reserved.沪ICP备15004866号-1沪公网安备310105020001112号Copyright © 2018 - 2019 www.xyz.com/public_html/site/wp-includes/plugin.php All rights reserved.沪ICP备15006666号-1Copyright © 2018 - 2019 www.xyz.com版权所有© 2019 www.woocommerce.com版权所有并保留所有权利include('/ home/customer/...')#5 /home/customer/www/ in /home/customer/www/xyz.com/public_html/site/wp-content/plugins/woocommerce-gateway-nab-dp/woocommerce-nab-dp.phpon line 946”

axzmvihb

axzmvihb1#

你提到的错误是因为你在orderId上调用get_items()而不是orderCall to a member function get_items() on int)。我不确定剩下的代码。

foreach( $order->get_items() as $order_item ) {
...
        }

相关问题