在 Woocommerce 中打印产品数组的值
Printing values of Product Array in Woocommerce
不幸的是,我在 pHp 中没有我想的那么坚强,所以我可能会问一个非常基本的问题。
我只是想弄清楚为什么我无法打印产品数组的各个值。
print_r($product) returns:
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);
希望对您有所帮助!
不幸的是,我在 pHp 中没有我想的那么坚强,所以我可能会问一个非常基本的问题。
我只是想弄清楚为什么我无法打印产品数组的各个值。
print_r($product) returns:
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);
希望对您有所帮助!