![](/img/trans.png)
[英]Get an array of unique product attributes/values with the highest price in WooCommerce
[英]Printing values of Product Array in Woocommerce
不幸的是,我没有像我想要的那样强大,所以我可能会问一个非常基本的问题。
我只想弄清楚为什么我不能打印产品数组的各个值。
print_r($ product)返回:
WC_Product_Simple Object (
[id] => 72
[post] => WP_Post Object (
[ID] => 72
[post_author] => 1
[post_date] => 2015-09-23 21:54:50
[post_date_gmt] => 2015-09-23 21:54:50
[post_content] =>
[post_title] => Simple Product #1
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => simple-product-1
[to_ping] =>
[pinged] =>
[post_modified] => 2015-09-23 21:55:48
[post_modified_gmt] => 2015-09-23 21:55:48
[post_content_filtered] =>
[post_parent] => 71
[guid] => http://brantbweb.com/?post_type=product&p=72
[menu_order] => 0
[post_type] => product
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
),
[product_type] => simple
[shipping_class:protected] =>
[shipping_class_id:protected] => 0
[downloadable] => no
[regular_price] => 10
[price] => 10
[tax_status] => taxable
[manage_stock] => no
[stock_status] => instock
)
我试过了
echo $product->post_parent;
但这不起作用。
所以我试过了
echo $product[0];
但是会出现错误。
我的感觉是,第一种选择是工作,只是以一种我没想到的方式,所以希望我可以得到解释为什么它不起作用,以及我应该做的事情。
谢谢!
根据您的结构,您有一个对象$ product,其中一个属性$ post是另一个对象,因此您可以尝试:
print_r($product->post->post_parent);
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.