Fix `Customers\DataStore::anonymize_customer` use of WC_Order instance as int (#38201)

This commit is contained in:
George Jipa 2024-09-05 22:56:48 +03:00 committed by GitHub
parent 61d41adf79
commit a7b957dbce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -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.

View File

@ -357,7 +357,7 @@ class WC_Privacy_Erasers {
* Allow extensions to remove their own personal data for this order. * Allow extensions to remove their own personal data for this order.
* *
* @since 3.4.0 * @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 ); do_action( 'woocommerce_privacy_remove_order_personal_data', $order );
} }

View File

@ -913,14 +913,18 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
* Anonymize the customer data for a single order. * Anonymize the customer data for a single order.
* *
* @internal * @internal
* @param int $order_id Order id. * @param int|WC_Order $order Order instance or ID.
* @return void * @return void
*/ */
public static function anonymize_customer( $order_id ) { public static function anonymize_customer( $order ) {
global $wpdb; global $wpdb;
if ( ! is_object( $order ) ) {
$order = wc_get_order( absint( $order ) );
}
$customer_id = $wpdb->get_var( $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 ) { if ( ! $customer_id ) {