From ff08d0ee4563f4154e89501dead4374a478915ad Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Tue, 26 Nov 2024 18:33:17 +0530 Subject: [PATCH 1/2] PRESS12-44 Added a GA event for WooPay connection. --- includes/Listeners/Commerce.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index 2c02fdc..239f319 100644 --- a/includes/Listeners/Commerce.php +++ b/includes/Listeners/Commerce.php @@ -27,6 +27,7 @@ public function register_hooks() { add_filter( 'update_option_ewc4wp_sso_account_status', array( $this, 'ecomdash_connected' ), 10, 2 ); add_filter( 'woocommerce_update_product', array( $this, 'product_created_or_updated' ), 100, 2 ); add_action( 'update_option_woocommerce_custom_orders_table_enabled', array( $this, 'woocommerce_hpos_enabled' ), 10, 3 ); + add_filter( 'pre_update_option_wcpay_account_connect_wpcom_connection_success', array( $this, 'woopay_connection' ), 10, 2 ); } /** @@ -329,4 +330,30 @@ public function woocommerce_hpos_enabled( $old_value, $new_value, string $option ); } } + + /** + * WooPay connected + * + * @param string $new_option New value of the woopay connection option + * @param string $old_option Old value of the woopay connection option + * + * @return string The new option value + */ + public function woopay_connection( $new_option, $old_option ) { + $url = is_ssl() ? 'https://' : 'http://'; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + 'label_key' => 'provider', + 'provider' => 'woopay', + 'page' => $url, + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + 'payment_connected', + $data + ); + } + + return $new_option; + } } From 51f4b55deee0a4b12abcd03b5fbcc814d282a051 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Thu, 5 Dec 2024 14:55:35 +0530 Subject: [PATCH 2/2] PRESS12-44 Updated the hook to trigger when wcpay_account_data is updated --- includes/Listeners/Commerce.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index 239f319..295564f 100644 --- a/includes/Listeners/Commerce.php +++ b/includes/Listeners/Commerce.php @@ -27,7 +27,7 @@ public function register_hooks() { add_filter( 'update_option_ewc4wp_sso_account_status', array( $this, 'ecomdash_connected' ), 10, 2 ); add_filter( 'woocommerce_update_product', array( $this, 'product_created_or_updated' ), 100, 2 ); add_action( 'update_option_woocommerce_custom_orders_table_enabled', array( $this, 'woocommerce_hpos_enabled' ), 10, 3 ); - add_filter( 'pre_update_option_wcpay_account_connect_wpcom_connection_success', array( $this, 'woopay_connection' ), 10, 2 ); + add_filter( 'update_option_wcpay_account_data', array( $this, 'woopay_connection' ), 10, 2 ); } /** @@ -347,7 +347,7 @@ public function woopay_connection( $new_option, $old_option ) { 'provider' => 'woopay', 'page' => $url, ); - if ( $new_option !== $old_option && ! empty( $new_option ) ) { + if ( empty( $old_option ) && ! empty( $new_option ) ) { $this->push( 'payment_connected', $data