From 0000d754c1f1f86fd2f9afc97fc9db20931925c4 Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Fri, 15 Mar 2024 15:43:05 +0100 Subject: [PATCH] Add snapshot tracking for Checkout additional fields. (#44310) * add snapshot tracking * add changelog * address feedback * Add changefile(s) from automation for the following project(s): woocommerce * update changelog * Add changefile(s) from automation for the following project(s): woocommerce * remove the extra changelog --------- Co-authored-by: github-actions --- .../add-tracking-for-additional-fields | 4 ++++ .../woocommerce/includes/class-wc-tracker.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-tracking-for-additional-fields diff --git a/plugins/woocommerce/changelog/add-tracking-for-additional-fields b/plugins/woocommerce/changelog/add-tracking-for-additional-fields new file mode 100644 index 00000000000..7440c721b43 --- /dev/null +++ b/plugins/woocommerce/changelog/add-tracking-for-additional-fields @@ -0,0 +1,4 @@ +Significance: patch +Type: add + +Adds Checkout additional fields to the store weekly snapshot. diff --git a/plugins/woocommerce/includes/class-wc-tracker.php b/plugins/woocommerce/includes/class-wc-tracker.php index cefe54ad0a5..c20a4c50e6f 100644 --- a/plugins/woocommerce/includes/class-wc-tracker.php +++ b/plugins/woocommerce/includes/class-wc-tracker.php @@ -15,6 +15,8 @@ use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore; use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil }; use Automattic\WooCommerce\Internal\Utilities\BlocksUtil; use Automattic\WooCommerce\Proxies\LegacyProxy; +use Automattic\WooCommerce\Blocks\Package; +use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields; defined( 'ABSPATH' ) || exit; @@ -1090,6 +1092,19 @@ class WC_Tracker { ); } + /** + * Get tracker data for additional fields on the checkout page. + * + * @return array Array of fields count and names. + */ + public static function get_checkout_additional_fields_data() { + $additional_fields_controller = Package::container()->get( CheckoutFields::class ); + + return array( + 'fields_count' => count( $additional_fields_controller->get_additional_fields() ), + 'fields_names' => array_keys( $additional_fields_controller->get_additional_fields() ), + ); + } /** * Get info about the cart & checkout pages. * @@ -1104,6 +1119,8 @@ class WC_Tracker { $pickup_location_data = self::get_pickup_location_data(); + $additional_fields_data = self::get_checkout_additional_fields_data(); + return array( 'cart_page_contains_cart_shortcode' => self::post_contains_text( $cart_page_id, @@ -1119,6 +1136,7 @@ class WC_Tracker { 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'], 'checkout_block_attributes' => $checkout_block_data['block_attributes'], 'pickup_location' => $pickup_location_data, + 'additional_fields' => $additional_fields_data, ); }