From 07f3f33566623aa4ecb6a72c183e95f287117f8a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 1 Feb 2019 15:43:24 -0200 Subject: [PATCH] Introduced new hooks for jetpack sync --- .../class-wc-admin-reports-coupons-data-store.php | 6 +++++- .../class-wc-admin-reports-customers-data-store.php | 10 ++++++++-- .../class-wc-admin-reports-orders-stats-data-store.php | 5 ++++- .../class-wc-admin-reports-products-data-store.php | 3 +++ .../class-wc-admin-reports-taxes-data-store.php | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php index 934ad18fcc6..f41a4a3547c 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php @@ -327,11 +327,13 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im $coupon_items = $order->get_items( 'coupon' ); foreach ( $coupon_items as $coupon_item ) { + $coupon_id = wc_get_coupon_id_by_code( $coupon_item->get_code() ); + $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, array( 'order_id' => $order_id, - 'coupon_id' => wc_get_coupon_id_by_code( $coupon_item->get_code() ), + 'coupon_id' => $coupon_id, 'discount_amount' => $coupon_item->get_discount(), 'date_created' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), ), @@ -342,6 +344,8 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im '%s', ) ); + + do_action( 'woocommerce_update_reports_coupon', $coupon_id, $order_id ); } } diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php index 1c0d3cba50f..25a1ae26a44 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php @@ -434,8 +434,11 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store '%s', ) ); + $customer_id = $wpdb->insert_id; - return $result ? $wpdb->insert_id : false; + do_action( 'woocommerce_new_reports_customer', $customer_id ); + + return $result ? $customer_id : false; } /** @@ -557,7 +560,10 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store $format[] = '%d'; } - return $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, $data, $format ); + $results = $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, $data, $format ); + + do_action( 'woocommerce_update_reports_customer', $customer_id ); + return $results; } /** diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php index ad9c425f197..5a4bac5113e 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php @@ -445,7 +445,10 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto } // Update or add the information to the DB. - return $wpdb->replace( $table_name, $data, $format ); + $results = $wpdb->replace( $table_name, $data, $format ); + + do_action( 'woocommerce_update_reports_order_stats', $order->get_id() ); + return $results; } /** 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 f663d8c366c..bece834f866 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 @@ -343,6 +343,7 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i array( 'order_item_id' => $order_item_id ), array( '%d' ) ); + do_action( 'woocommerce_delete_reports_product', $order_item_id, $order->get_id() ); } else { $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, @@ -367,6 +368,8 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i '%s', ) ); + + do_action( 'woocommerce_update_reports_product', $order_item_id, $order->get_id() ); } } } diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php index f5323f7536d..ac9278e8405 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php @@ -284,6 +284,8 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl '%f', ) ); + + do_action( 'woocommerce_update_reports_tax', $tax_item->get_rate_id(), $order->get_id() ); } }