从 WooCommerce 对象获取数据

发布于 2025-01-14 12:39:56 字数 2306 浏览 5 评论 0原文

我正在努力从 wc_get_orders() 获取特定数据。

这是代码:

$args   = array(
    'numberposts' => - 1,
    'orderby'     => 'date',
    'order'       => 'DESC',
    'customer_id' => get_current_user_id(),
);
$orders = wc_get_orders( $args );
echo '<pre>', var_dump( $orders ), '</pre>';

这是对象的一部分:

["meta_data":protected]=>
    array(4) {
      [0]=>
      object(WC_Meta_Data)#3544 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
      }
      [1]=>
      object(WC_Meta_Data)#3545 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
      }
      [2]=>
      object(WC_Meta_Data)#3546 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
      }
      [3]=>

我正在尝试获取 tip_korisinka 的值,该值位于似乎受保护的 WC_Meta_Data 内部。检查此屏幕截图: https://prnt.sc/CI-UfqEkuuag

这是没有的解决方案之一到目前为止我尝试过的成功:

foreach ( $orders as $key => $value ) {
    echo $key->$value['tip_korisnika'];
}

任何帮助将不胜感激。

I'm struggling to get specific data from wc_get_orders().

Here is the code:

$args   = array(
    'numberposts' => - 1,
    'orderby'     => 'date',
    'order'       => 'DESC',
    'customer_id' => get_current_user_id(),
);
$orders = wc_get_orders( $args );
echo '<pre>', var_dump( $orders ), '</pre>';

Here is the part of the object:

["meta_data":protected]=>
    array(4) {
      [0]=>
      object(WC_Meta_Data)#3544 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
      }
      [1]=>
      object(WC_Meta_Data)#3545 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
      }
      [2]=>
      object(WC_Meta_Data)#3546 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
      }
      [3]=>

I'm trying to get the value of tip_korisinka, which is inside WC_Meta_Data that seems to be protected. Check this screenshot: https://prnt.sc/CI-UfqEkuuag

This is one of the solutions without success that I have tried so far:

foreach ( $orders as $key => $value ) {
    echo $key->$value['tip_korisnika'];
}

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文