wc_get_product_id_by_sku not working anymore
-
I’m working on a script that retrieves an external CSV file and then processes that into the database. I need the function wc_get_product_id_by_sku to get the product ID.
Everything worked when using this steps:
Retrieve the file with CURL
Process a few things
Use the function wc_get_product_id_by_sku()
But, since I wanted to use the WordPress function wp_remote_request(), I get the following Error:Fatal error: Uncaught Error: Call to undefined function wc_get_product_id_by_sku() in /sites/..
Everything else remains the same and works!Do these functions interfere with each other? How is it possible that it works one way, but not the other way around?
$response = wp_remote_request( $host ); $result = wp_remote_retrieve_body($response); if(empty($result)) { exit; } // Default: CSV has a top row $toprow = true; // Get settings for the CSV fields $sku = get_option('blabla_sku'); // Parse CSV into array $rows = array_map('str_getcsv', explode("\n", $result)); if($toprow) { $header = array_shift($rows); $products = array(); foreach ($rows as $row) { $products[] = array_combine($header, $row); } } else { $products = $rows; } foreach($products as $product) { if(wc_get_product_id_by_sku($product[$sku]) !== 0) { // Do something } }
- The topic ‘wc_get_product_id_by_sku not working anymore’ is closed to new replies.