php – Get woocommerce price of a product gives strange error
Question
I get the products like this:
$args = array(
'category' => array("everything" ),
'orderby' => 'name',
);
$products = wc_get_products( $args );
print_r($products); // I see all the products.. name, description, price, regular_price..
here print_r($products[0]);
WC_Product_Simple Object
(
[object_type:protected] => product
[post_type:protected] => product
[cache_group:protected] => products
[data:protected] => Array
(
[name] => My Damn Product
[slug] => goddamnItWhereIsYourFCKINGprice?
[date_created] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2022-10-29 22:00:11.000000
[timezone_type] => 1
[timezone] => +00:00
)
[date_modified] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2022-10-29 22:04:13.000000
[timezone_type] => 1
[timezone] => +00:00
)
[status] => publish
[featured] =>
[catalog_visibility] => visible
[description] =>
[short_description] =>
[sku] =>
[price] => 22
[regular_price] => 22
//...
now I want to get the name of the first product:
print($products[0]->name); // gives "My Damn Product Name"
now I want to get the price of the first product:
print($products[0]->price); //NOW everything explodes..
Fatal error: Uncaught Error: Call to undefined function
wc_empty_cart() in C:\Users\user\Local
Sites\Site\app\public\wp-content\plugins\woocommerce\includes\class-wc-session-handler.php
on line 372 ( ! ) Error: Call to undefined function wc_empty_cart() in
C:\Users\user\Local
Sites\Site\app\public\wp-content\plugins\woocommerce\includes\class-wc-session-handler.php
on line 372
0
11 months
2022-11-05T12:58:10-05:00
2022-11-05T12:58:10-05:00 0 Answers
0 views
0
Leave an answer