get_product_from_item($item) deprecated replacement in WooCommerce

Viewed 5643

I'm trying to fix some deprecated functions from this unsupported SagePay plugin.

How can I replace the following snippet of deprecated code in WooCommerce?

foreach ($order->get_items() as $item) {
if ($item['qty']) {
  $product = $order->get_product_from_item($item);

I can see that this is its replacement:

@deprecated Add deprecation notices in future release. Replaced with $item->get_product()

But simply changing it to $product = $item->get_product(); doesn't work. I've also tried changing that line to:

$product = wc_get_product($item['id']);

But it causes an internal server error during the checkout.

1 Answers
Related