From a7b957dbce68fbcdf56c2a3713d71f90a1962851 Mon Sep 17 00:00:00 2001 From: George Jipa Date: Thu, 5 Sep 2024 22:56:48 +0300 Subject: [PATCH] Fix `Customers\DataStore::anonymize_customer` use of WC_Order instance as int (#38201) --- plugins/woocommerce/changelog/fix-anonymize-customer | 4 ++++ .../woocommerce/includes/class-wc-privacy-erasers.php | 2 +- .../src/Admin/API/Reports/Customers/DataStore.php | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-anonymize-customer diff --git a/plugins/woocommerce/changelog/fix-anonymize-customer b/plugins/woocommerce/changelog/fix-anonymize-customer new file mode 100644 index 00000000000..82b4668282c --- /dev/null +++ b/plugins/woocommerce/changelog/fix-anonymize-customer @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Make Admin\API\Reports\Customers\DataStore::anonymize_customer accept an order instance as a parameter to ensure compatibility with the `woocommerce_privacy_remove_order_personal_data` hook. diff --git a/plugins/woocommerce/includes/class-wc-privacy-erasers.php b/plugins/woocommerce/includes/class-wc-privacy-erasers.php index 69cba905dce..3d43ff6052d 100644 --- a/plugins/woocommerce/includes/class-wc-privacy-erasers.php +++ b/plugins/woocommerce/includes/class-wc-privacy-erasers.php @@ -357,7 +357,7 @@ class WC_Privacy_Erasers { * Allow extensions to remove their own personal data for this order. * * @since 3.4.0 - * @param WC_Order $order A customer object. + * @param WC_Order $order Order instance. */ do_action( 'woocommerce_privacy_remove_order_personal_data', $order ); } diff --git a/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php b/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php index fac1fdaa961..e13ed41c47c 100644 --- a/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php +++ b/plugins/woocommerce/src/Admin/API/Reports/Customers/DataStore.php @@ -913,14 +913,18 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { * Anonymize the customer data for a single order. * * @internal - * @param int $order_id Order id. + * @param int|WC_Order $order Order instance or ID. * @return void */ - public static function anonymize_customer( $order_id ) { + public static function anonymize_customer( $order ) { global $wpdb; + if ( ! is_object( $order ) ) { + $order = wc_get_order( absint( $order ) ); + } + $customer_id = $wpdb->get_var( - $wpdb->prepare( "SELECT customer_id FROM {$wpdb->prefix}wc_order_stats WHERE order_id = %d", $order_id ) + $wpdb->prepare( "SELECT customer_id FROM {$wpdb->prefix}wc_order_stats WHERE order_id = %d", $order->get_id() ) ); if ( ! $customer_id ) {