从 WooCommerce 对象获取数据
我正在努力从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论