From b1890190c7b7246db1e336e923eb46b7b7eafaeb Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Wed, 6 Mar 2019 16:03:54 +0800 Subject: [PATCH] Get product ID for line item from meta table instead of deleting --- ...s-wc-admin-reports-products-data-store.php | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php index e775fdb3ae0..19f87a3ecd7 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php @@ -90,7 +90,6 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i */ public static function init() { add_action( 'woocommerce_reports_delete_order_stats', array( __CLASS__, 'sync_on_order_delete' ), 10 ); - add_action( 'delete_post', array( __CLASS__, 'delete_product_id' ) ); } /** @@ -403,8 +402,8 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i array( 'order_item_id' => $order_item_id, 'order_id' => $order->get_id(), - 'product_id' => $order_item->get_product_id( 'edit' ), - 'variation_id' => $order_item->get_variation_id( 'edit' ), + 'product_id' => wc_get_order_item_meta( $order_item_id, '_product_id' ), + 'variation_id' => wc_get_order_item_meta( $order_item_id, '_variation_id' ), 'customer_id' => ( 0 < $order->get_customer_id( 'edit' ) ) ? $order->get_customer_id( 'edit' ) : null, 'product_qty' => $product_qty, 'product_net_revenue' => $net_revenue, @@ -475,24 +474,4 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i */ do_action( 'woocommerce_reports_delete_product', 0, $order_id ); } - - /** - * Deletes the product ID when a product is deleted. - * This keeps data consistent if it gets resynced at any point. - * - * @param int $post_id Post ID. - */ - public static function delete_product_id( $post_id ) { - global $wpdb; - - if ( 'product' !== get_post_type( $post_id ) ) { - return; - } - - $wpdb->update( - $wpdb->prefix . self::TABLE_NAME, - array( 'product_id' => 0 ), - array( 'product_id' => $post_id ) - ); - } }