on WooCommerce, I'm trying to get the variation name of a product. But I'm getting the message error : Call to undefined function wc_get_product(). Here is the code: (the file where this code is, is from a application that make some request to the server, so it isn't on the root directory).
$order_items = $order_data->line_items;
foreach ($order_items as $order_item) {
if ($order_item->product_id == $product_id) {
// Get variation if any
$variation_id = $order_item->variation_id;
$variation_name = wc_get_product($variation_id);
$variation_name->get_formatted_name();
if (empty($variation_id)) $variation_id = 0;
$variation_prop = $product['variations'][$variation_id];
}
}
Any help is appreciated.
EDITED 2: The $order_data is got this way:
try {
$woocommerce = new Client($f3->get('wprestbaseurl'), $f3->get('wprestconsumer_key'), $f3->get('wpconsumer_secret'), ['wp_api' => true, 'version' => 'wc/v3', 'query_string_auth' => (0 === strpos(strtolower($f3->get('wprestbaseurl')), 'https://'))]);
// Retrieve given order meta data
// System IDs are stored into the "xlspadlock_activations" custom field for each order.
$order_data = $woocommerce->get("orders/$customer_order_id");
}
catch{....