Wednesday, February 15, 2023
HomeWordPress Developmentphp - $product->get_price() is giving Name to undefined operate wc_empty_cart() within the...

php – $product->get_price() is giving Name to undefined operate wc_empty_cart() within the loop


$merchandise = wc_get_products( $args );
  header('Content material-Kind: utility/json; charset=utf-8');
  $product_data = array();
  foreach ($merchandise as $product) {
      $image_id = $product->get_image_id();
      $image_url = $image_id ? wp_get_attachment_image_src($image_id, 'full')[0] : '';
      $product_data[] = array(
          'id' => $product->get_id(),
          'identify' => $product->get_name(),
          'value' => $product->get_price(),
          'description' => $product->get_description(),
          'custom_url' => $product->get_meta('woocommerce_custom_field'),
          'image_url' => $image_url
      );
  }
  // Convert the product knowledge right into a JSON response
  $json_response = json_encode($product_data,JSON_UNESCAPED_SLASHES);
  // Return the JSON response
  echo $json_response;

I attempt to return an inventory of merchandise as json.. all the pieces works tremendous, however not the road with $product->get_price();

eradicating the road and all the pieces works… however I would like the worth as effectively! Unusual factor is that this labored just a few minutes in the past, however now it is simply not working… identical as with $product->get_html_price()…

Error:


( ! ) Deadly error: Uncaught Error: Name to undefined operate wc_empty_cart() in C:UsersxxLocal Sitesyyapppublicwp-contentpluginswoocommerceincludesclass-wc-session-handler.php on line 372
( ! ) Error: Name to undefined operate wc_empty_cart() in C:UsersxxLocal Sitesyyapppublicwp-contentpluginswoocommerceincludesclass-wc-session-handler.php on line 372
Name Stack
#   Time    Reminiscence  Perform    Location
1   0.0001  368296  {principal}( )   ...index.php:0
2   0.0001  368576  require( 'C:UsersxxLocal Sitesyyapppublicwp-blog-header.php' )   ...index.php:17
3   0.5579  22690256    wp( )   ...wp-blog-header.php:16
4   0.5579  22690256    WP->principal( ) ...capabilities.php:1332
5   0.5579  22690256    WP->parse_request( )    ...class-wp.php:780
6   0.5582  22729648    do_action_ref_array( )  ...class-wp.php:399
7   0.5582  22729648    WP_Hook->do_action( )   ...plugin.php:565
8   0.5582  22729648    WP_Hook->apply_filters( )   ...class-wp-hook.php:332
9   0.5582  22730808    rest_api_loaded( )  ...class-wp-hook.php:308
10  1.4264  33766464    WP_REST_Server->serve_request( )    ...rest-api.php:410
11  1.4271  33763672    WP_REST_Server->dispatch( ) ...class-wp-rest-server.php:442
12  1.4276  33764800    WP_REST_Server->respond_to_request( )   ...class-wp-rest-server.php:1018
13  1.4276  33764800    jsonProducts( ) ...class-wp-rest-server.php:1171
14  1.4451  34002856    WC_Product_Simple->get_price( ) ...myProductsEndpoint.php:76
15  1.4451  34002856    WC_Product_Simple->get_prop( )  ...abstract-wc-product.php:270
16  1.4451  34002912    apply_filters( )    ...abstract-wc-data.php:821
17  1.4451  34003320    WP_Hook->apply_filters( )   ...plugin.php:205
18  1.4452  34004856    WCPayMultiCurrencyFrontendPrices->get_product_price_string( ) ...class-wp-hook.php:308
19  1.4452  34004856    WCPayMultiCurrencyFrontendPrices->get_product_price( )    ...FrontendPrices.php:96
20  1.4452  34004936    WCPayMultiCurrencyMultiCurrency->get_price( ) ...FrontendPrices.php:84
21  1.4452  34004936    WCPayMultiCurrencyMultiCurrency->get_selected_currency( ) ...MultiCurrency.php:721
22  1.4452  34004936    WCPayMultiCurrencyMultiCurrency->get_stored_currency_code( )  ...MultiCurrency.php:616
23  1.4452  34004936    WooCommerce->initialize_session( )  ...MultiCurrency.php:916
24  1.4454  34007736    WC_Session_Handler->init( ) ...class-woocommerce.php:862
25  1.4454  34007736    WC_Session_Handler->init_session_cookie( )  ...class-wc-session-handler.php:71
26  1.4469  34061704    WC_Session_Handler->destroy_session( )  ...class-wc-session-handler.php:99
27  1.4515  34024672    WC_Session_Handler->forget_session( )   ...class-wc-session-handler.php:363

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments