From 2efe0a0f6a7c944164fb4d4b04f63bb6a647219b Mon Sep 17 00:00:00 2001 From: Nadir Seghir Date: Wed, 15 Feb 2023 16:36:56 +0100 Subject: [PATCH] add tracking for local pickup --- .../changelog/add-tracking-for-loca-pickup | 4 +++ .../woocommerce/includes/class-wc-tracker.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-tracking-for-loca-pickup diff --git a/plugins/woocommerce/changelog/add-tracking-for-loca-pickup b/plugins/woocommerce/changelog/add-tracking-for-loca-pickup new file mode 100644 index 00000000000..20ccbdbeb1f --- /dev/null +++ b/plugins/woocommerce/changelog/add-tracking-for-loca-pickup @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak + +Add tracking for local pickup method in Checkout diff --git a/plugins/woocommerce/includes/class-wc-tracker.php b/plugins/woocommerce/includes/class-wc-tracker.php index abad47fe2e8..15b99f056b7 100644 --- a/plugins/woocommerce/includes/class-wc-tracker.php +++ b/plugins/woocommerce/includes/class-wc-tracker.php @@ -790,6 +790,31 @@ class WC_Tracker { ); } + /** + * Get tracker data for a pickup location method. + * + * @return array Associative array of tracker data with keys: + * - page_contains_block + * - block_attributes + */ + public static function get_pickup_location_data( $block_name, $woo_page_name ) { + $pickup_location_enabled = false; + $pickup_locations_count = count( get_option( 'pickup_location_pickup_locations', [] ) ); + + // Get the available shipping methods + $shipping_methods = WC()->shipping()->get_shipping_methods(); + + // Check if the desired shipping method is enabled + if ( isset( $shipping_methods['pickup_location'] ) && $shipping_methods['pickup_location']->is_enabled()) { + $pickup_location_enabled = true; + } + + return array( + 'pickup_location_enabled' => $pickup_location_enabled, + 'pickup_locations_count' => $pickup_locations_count, + ); + } + /** * Get info about the cart & checkout pages. * @@ -802,6 +827,8 @@ class WC_Tracker { $cart_block_data = self::get_block_tracker_data( 'woocommerce/cart', 'cart' ); $checkout_block_data = self::get_block_tracker_data( 'woocommerce/checkout', 'checkout' ); + $pickup_location_data = self::get_pickup_location_data(); + return array( 'cart_page_contains_cart_shortcode' => self::post_contains_text( $cart_page_id, @@ -816,6 +843,7 @@ class WC_Tracker { 'cart_block_attributes' => $cart_block_data['block_attributes'], 'checkout_page_contains_checkout_block' => $checkout_block_data['page_contains_block'], 'checkout_block_attributes' => $checkout_block_data['block_attributes'], + 'pickup_location' => $pickup_location_data, ); }