php – get woocommerce price of a product gives strange error

I get 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($product)[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 first product name:

  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() C:\Users\user\Local Sites\Site\app\public\wp-content\plugins\woocommerce\includes\class-wc-session-handler Error on line 372 ( ! ) .php: Undefined function wc_empty_cart( ! ) in C:\Users\user\Local Sites\Site\app\public\wp-content\plugins\woocommerce\includes\class-wc-session-handler.php ) call line 372 . Feather

Leave a Comment