Automattic / Automattic/jetpack

WooCommerce Analytics: deprecated code

Open
#17,071 7 comments 2 reactions 1 assignee Claimed by @haszari View on GitHub
[Feature] WooCommerce Analytics [Pri] Low Bug
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

A user reported the following error on the checkout page of their WooCommerce site after updating to v 4.4.0, and using Jetpack 8.8.2:

`Deprecated: WC_Abstract_Legacy_Order::get_product_from_item is deprecated since version 4.4.0! Use $item->get_product() instead. in C:\Utilities\laragon\www\arteescorp\wp-includes\functions.php on line 4773`

They traced the error to this file:

`...\wp-content\plugins\jetpack\modules\woocommerce-analytics\classes\class-jetpack-woocommerce-analytics-universal.php (1 hit)
Line 283: $product = $order->get_product_from_item( $order_item );`

Modifying that line as follows causes the error to go away:

`Line 283: $product = $order_item->get_product();`

I've not been able to replicate this error on a test site running WooCommerce 4.4.1 and Jetpack 8.9, but three different users reported it, and that the proposed fix resolved it. They were not able to provide steps to replicate - the error apparently just appears on the checkout page.

The file at https://github.com/Automattic/jetpack/blob/cfaf0497e9b20c931e8ad1959008bdb03a03962d/modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php#L283 still references `get_product_from_item` in the current version of Jetpack.

Reported via https://wordpress.org/support/topic/deprecated-wc_abstract_legacy_orderget_product_from_item-is-deprecated-since/

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.