From 31add067e39c055591c17a3a1c1acdc6e77171c9 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Fri, 29 Mar 2024 17:15:22 +0530 Subject: [PATCH 1/8] Wonder cart events to send data to hiive --- includes/Listeners/Commerce.php | 52 +++++++++++++++++++++ includes/Listeners/WonderCart.php | 76 +++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index 94dd097..e368f99 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' ) ); 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_action( 'woocommerce_before_checkout_form', array( $this,'checkout_campaigns_used') ); } /** @@ -329,4 +330,55 @@ public function woocommerce_hpos_enabled( $old_value, $new_value, $option ) { ); } } + + /** + * Track wonder_cart campaigns used in checkout page + * Send data to hiive + + * @return void + */ + public function checkout_campaigns_used() { + $campaigns = array(); + $campaign_total = 0; + + $cart = WC()->cart; + + // To track Cart Discount + foreach($cart->get_applied_coupons() as $coupon_item){ + array_push($campaigns,$coupon_item); + $campaign_total += $cart->coupon_discount_totals[$coupon_item]; + } + + //To track free shipping campaign ( Using reflection to access protected properties) + $reflection_class = new \ReflectionClass($cart); + $shipping_methods_property = $reflection_class->getProperty('shipping_methods'); + $shipping_methods_property->setAccessible(true); + $shipping_methods = $shipping_methods_property->getValue($cart); + foreach ($shipping_methods as $shipping_method) { + if ($shipping_method->id === 'yith_sales_free_shipping'){ + array_push($campaigns,'yith_sales_free_shipping'); + } + } + + //To track rest of the campaigns + foreach ($cart->get_cart() as $cart_item_key => $cart_item) { + if (isset($cart_item['yith_sales']) && isset($cart_item['yith_sales']['campaigns'])) { + $campaign_type = $cart_item['yith_sales_discounts']['type']; + array_push($campaigns,$campaign_type); + $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; + } + } + + $data = array( + 'label_key' => 'campaign_type', + 'campaign_type' => array_unique($campaigns), + 'campaign_count' => count($campaigns), + 'campaign_total' => '$'.$campaign_total + ); + $this->push( + "checkout_campaign_type", + "wonder_cart", + $data + ); + } } diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 428380f..6244da0 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -14,6 +14,9 @@ class WonderCart extends Listener { */ public function register_hooks() { add_action('rest_after_insert_yith_campaign', array( $this, 'register_campaign' ), 10 ); + add_action('yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); + add_action('yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); + add_action('yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); } /** @@ -41,4 +44,77 @@ public function register_campaign( $post){ return $post; } + + /** + * Track wonder_cart create campaign modal window open + * Send data to hiive + + * @param string $args A list of details that were involved on the event. + * @param string $event The name of the event. + + * @return void + */ + public function create_campaign_modal_open($args, $event) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + + $data = array( + "label_key" => "trigger", + "trigger" => 'Campaign Modal Open', + "page" => $url + ); + + $this->push( + 'modal_open', + 'wonder_cart', + $data + ); + } + + /** + * Track wonder_cart campaign selection + * Send data to hiive + + * @param string $args A list of details that were involved on the event. + * @param string $event The name of the event. + + * @return void + */ + public function campaign_selected($args, $event) { + $data = array( + "label_key" => "campaign_slug", + "campaign_type" => $args['type'], + "campaign_slug" => $args['type'] + ); + + $this->push( + 'campaign_selected', + 'wonder_cart', + $data + ); + + } + + /** + * Track wonder_cart campaign abondoned + * Send data to hiive + + * @param string $args A list of details that were involved on the event. + * @param string $event The name of the event. + + * @return void + */ + public function campaign_abandoned($args, $event) { + $data = array( + 'label_key' => 'campaign_slug', + 'campaign_type' => $args['type'], + 'campaign_slug' => $args['type']."-".$args['id'] + ); + + $this->push( + 'campaign_abondoned', + 'wonder_cart', + $data + ); + } } From acdfb42b0fce0c6bc0369923705425eba49d27d3 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Fri, 29 Mar 2024 17:47:39 +0530 Subject: [PATCH 2/8] Lint fixes --- includes/Listeners/Commerce.php | 48 +++++++++++------------ includes/Listeners/WonderCart.php | 63 +++++++++++++++---------------- 2 files changed, 55 insertions(+), 56 deletions(-) diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index e368f99..4ad2012 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' ) ); 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_action( 'woocommerce_before_checkout_form', array( $this,'checkout_campaigns_used') ); + add_action( 'woocommerce_before_checkout_form', array( $this, 'checkout_campaigns_used' ) ); } /** @@ -338,47 +338,47 @@ public function woocommerce_hpos_enabled( $old_value, $new_value, $option ) { * @return void */ public function checkout_campaigns_used() { - $campaigns = array(); + $campaigns = array(); $campaign_total = 0; $cart = WC()->cart; // To track Cart Discount - foreach($cart->get_applied_coupons() as $coupon_item){ - array_push($campaigns,$coupon_item); - $campaign_total += $cart->coupon_discount_totals[$coupon_item]; + foreach ( $cart->get_applied_coupons() as $coupon_item ) { + array_push( $campaigns, $coupon_item ); + $campaign_total += $cart->coupon_discount_totals[ $coupon_item ]; } - - //To track free shipping campaign ( Using reflection to access protected properties) - $reflection_class = new \ReflectionClass($cart); - $shipping_methods_property = $reflection_class->getProperty('shipping_methods'); - $shipping_methods_property->setAccessible(true); - $shipping_methods = $shipping_methods_property->getValue($cart); - foreach ($shipping_methods as $shipping_method) { - if ($shipping_method->id === 'yith_sales_free_shipping'){ - array_push($campaigns,'yith_sales_free_shipping'); + + // To track free shipping campaign ( Using reflection to access protected properties) + $reflection_class = new \ReflectionClass( $cart ); + $shipping_methods_property = $reflection_class->getProperty( 'shipping_methods' ); + $shipping_methods_property->setAccessible( true ); + $shipping_methods = $shipping_methods_property->getValue( $cart ); + foreach ( $shipping_methods as $shipping_method ) { + if ( 'yith_sales_free_shipping' === $shipping_method->id ) { + array_push( $campaigns, 'yith_sales_free_shipping' ); } } - //To track rest of the campaigns - foreach ($cart->get_cart() as $cart_item_key => $cart_item) { - if (isset($cart_item['yith_sales']) && isset($cart_item['yith_sales']['campaigns'])) { + // To track rest of the campaigns + foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { + if ( isset( $cart_item['yith_sales'] ) && isset( $cart_item['yith_sales']['campaigns'] ) ) { $campaign_type = $cart_item['yith_sales_discounts']['type']; - array_push($campaigns,$campaign_type); + array_push( $campaigns, $campaign_type ); $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; } } $data = array( 'label_key' => 'campaign_type', - 'campaign_type' => array_unique($campaigns), - 'campaign_count' => count($campaigns), - 'campaign_total' => '$'.$campaign_total + 'campaign_type' => array_unique( $campaigns ), + 'campaign_count' => count( $campaigns ), + 'campaign_total' => '$' . $campaign_total, ); $this->push( - "checkout_campaign_type", - "wonder_cart", - $data + 'checkout_campaign_type', + 'wonder_cart', + $data ); } } diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 6244da0..1a93c8b 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -13,35 +13,35 @@ class WonderCart extends Listener { * @return void */ public function register_hooks() { - add_action('rest_after_insert_yith_campaign', array( $this, 'register_campaign' ), 10 ); - add_action('yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); - add_action('yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); - add_action('yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); + add_action( 'rest_after_insert_yith_campaign', array( $this, 'register_campaign' ), 10 ); + add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); + add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); + add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); } /** * Campaign created * - * @param string $post + * @param string $post Campaign data * * @return string The post value */ - public function register_campaign( $post){ - $campaign = yith_sales_get_campaign( $post->ID ); - if ($campaign){ + public function register_campaign( $post ) { + $campaign = yith_sales_get_campaign( $post->ID ); + if ( $campaign ) { $type = $campaign->get_type(); - + $data = array( - "label_key"=> "type", - "type"=> $type, + 'label_key' => 'type', + 'type' => $type, ); - + $this->push( - "campaign_created", + 'campaign_created', $data ); } - + return $post; } @@ -49,24 +49,24 @@ public function register_campaign( $post){ * Track wonder_cart create campaign modal window open * Send data to hiive - * @param string $args A list of details that were involved on the event. + * @param string $args A list of details that were involved on the event. * @param string $event The name of the event. * @return void */ - public function create_campaign_modal_open($args, $event) { - $url = is_ssl() ? "https://" : "http://"; + public function create_campaign_modal_open( $args, $event ) { + $url = is_ssl() ? 'https://' : 'http://'; $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $data = array( - "label_key" => "trigger", - "trigger" => 'Campaign Modal Open', - "page" => $url + 'label_key' => 'trigger', + 'trigger' => 'Campaign Modal Open', + 'page' => $url, ); $this->push( 'modal_open', - 'wonder_cart', + 'wonder_cart', $data ); } @@ -75,45 +75,44 @@ public function create_campaign_modal_open($args, $event) { * Track wonder_cart campaign selection * Send data to hiive - * @param string $args A list of details that were involved on the event. + * @param string $args A list of details that were involved on the event. * @param string $event The name of the event. * @return void */ - public function campaign_selected($args, $event) { + public function campaign_selected( $args, $event ) { $data = array( - "label_key" => "campaign_slug", - "campaign_type" => $args['type'], - "campaign_slug" => $args['type'] + 'label_key' => 'campaign_slug', + 'campaign_type' => $args['type'], + 'campaign_slug' => $args['type'], ); $this->push( 'campaign_selected', - 'wonder_cart', + 'wonder_cart', $data ); - } /** * Track wonder_cart campaign abondoned * Send data to hiive - * @param string $args A list of details that were involved on the event. + * @param string $args A list of details that were involved on the event. * @param string $event The name of the event. * @return void */ - public function campaign_abandoned($args, $event) { + public function campaign_abandoned( $args, $event ) { $data = array( 'label_key' => 'campaign_slug', 'campaign_type' => $args['type'], - 'campaign_slug' => $args['type']."-".$args['id'] + 'campaign_slug' => $args['type'] . '-' . $args['id'], ); $this->push( 'campaign_abondoned', - 'wonder_cart', + 'wonder_cart', $data ); } From d0c0b543dadf9463cbf504786ec239c0b14c3a76 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Mon, 1 Apr 2024 15:12:16 +0530 Subject: [PATCH 3/8] Moved checkout_campaigns_used action to WonderCart --- includes/Listeners/Commerce.php | 52 ----------------------------- includes/Listeners/WonderCart.php | 54 +++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index 4ad2012..94dd097 100644 --- a/includes/Listeners/Commerce.php +++ b/includes/Listeners/Commerce.php @@ -27,7 +27,6 @@ public function register_hooks() { add_filter( 'update_option_ewc4wp_sso_account_status', array( $this, 'ecomdash_connected' ) ); 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_action( 'woocommerce_before_checkout_form', array( $this, 'checkout_campaigns_used' ) ); } /** @@ -330,55 +329,4 @@ public function woocommerce_hpos_enabled( $old_value, $new_value, $option ) { ); } } - - /** - * Track wonder_cart campaigns used in checkout page - * Send data to hiive - - * @return void - */ - public function checkout_campaigns_used() { - $campaigns = array(); - $campaign_total = 0; - - $cart = WC()->cart; - - // To track Cart Discount - foreach ( $cart->get_applied_coupons() as $coupon_item ) { - array_push( $campaigns, $coupon_item ); - $campaign_total += $cart->coupon_discount_totals[ $coupon_item ]; - } - - // To track free shipping campaign ( Using reflection to access protected properties) - $reflection_class = new \ReflectionClass( $cart ); - $shipping_methods_property = $reflection_class->getProperty( 'shipping_methods' ); - $shipping_methods_property->setAccessible( true ); - $shipping_methods = $shipping_methods_property->getValue( $cart ); - foreach ( $shipping_methods as $shipping_method ) { - if ( 'yith_sales_free_shipping' === $shipping_method->id ) { - array_push( $campaigns, 'yith_sales_free_shipping' ); - } - } - - // To track rest of the campaigns - foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { - if ( isset( $cart_item['yith_sales'] ) && isset( $cart_item['yith_sales']['campaigns'] ) ) { - $campaign_type = $cart_item['yith_sales_discounts']['type']; - array_push( $campaigns, $campaign_type ); - $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; - } - } - - $data = array( - 'label_key' => 'campaign_type', - 'campaign_type' => array_unique( $campaigns ), - 'campaign_count' => count( $campaigns ), - 'campaign_total' => '$' . $campaign_total, - ); - $this->push( - 'checkout_campaign_type', - 'wonder_cart', - $data - ); - } } diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 1a93c8b..ceab5a7 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -17,6 +17,7 @@ public function register_hooks() { add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); + add_action( 'woocommerce_before_checkout_form', array( $this, 'checkout_campaigns_used' ) ); } /** @@ -66,7 +67,6 @@ public function create_campaign_modal_open( $args, $event ) { $this->push( 'modal_open', - 'wonder_cart', $data ); } @@ -89,7 +89,6 @@ public function campaign_selected( $args, $event ) { $this->push( 'campaign_selected', - 'wonder_cart', $data ); } @@ -112,7 +111,56 @@ public function campaign_abandoned( $args, $event ) { $this->push( 'campaign_abondoned', - 'wonder_cart', + $data + ); + } + + /** + * Track wonder_cart campaigns used in checkout page + * Send data to hiive + + * @return void + */ + public function checkout_campaigns_used() { + $campaigns = array(); + $campaign_total = 0; + + $cart = WC()->cart; + + // To track Cart Discount + foreach ( $cart->get_applied_coupons() as $coupon_item ) { + array_push( $campaigns, $coupon_item ); + $campaign_total += $cart->coupon_discount_totals[ $coupon_item ]; + } + + // To track free shipping campaign ( Using reflection to access protected properties) + $reflection_class = new \ReflectionClass( $cart ); + $shipping_methods_property = $reflection_class->getProperty( 'shipping_methods' ); + $shipping_methods_property->setAccessible( true ); + $shipping_methods = $shipping_methods_property->getValue( $cart ); + foreach ( $shipping_methods as $shipping_method ) { + if ( 'yith_sales_free_shipping' === $shipping_method->id ) { + array_push( $campaigns, 'yith_sales_free_shipping' ); + } + } + + // To track rest of the campaigns + foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { + if ( isset( $cart_item['yith_sales'] ) && isset( $cart_item['yith_sales']['campaigns'] ) ) { + $campaign_type = $cart_item['yith_sales_discounts']['type']; + array_push( $campaigns, $campaign_type ); + $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; + } + } + + $data = array( + 'label_key' => 'campaign_type', + 'campaign_type' => array_unique( $campaigns ), + 'campaign_count' => count( $campaigns ), + 'campaign_total' => '$' . $campaign_total, + ); + $this->push( + 'checkout_campaign_type', $data ); } From 1eebdee4de77119ba1b2e18d9a2fa5ff40a4ce9a Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Mon, 15 Apr 2024 19:04:25 +0530 Subject: [PATCH 4/8] Updated hook to trigger only when the order is processed. --- includes/Listeners/WonderCart.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index ceab5a7..43dc4b7 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -17,7 +17,7 @@ public function register_hooks() { add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); - add_action( 'woocommerce_before_checkout_form', array( $this, 'checkout_campaigns_used' ) ); + add_action( 'woocommerce_checkout_order_processed', array( $this,'checkout_campaigns_used' ), 10, 1 ); } /** @@ -152,16 +152,17 @@ public function checkout_campaigns_used() { $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; } } - - $data = array( - 'label_key' => 'campaign_type', - 'campaign_type' => array_unique( $campaigns ), - 'campaign_count' => count( $campaigns ), - 'campaign_total' => '$' . $campaign_total, - ); - $this->push( - 'checkout_campaign_type', - $data - ); + if( count( $campaigns ) > 0 ) { + $data = array( + 'label_key' => 'campaign_type', + 'campaign_type' => array_unique( $campaigns ), + 'campaign_count' => count( $campaigns ), + 'campaign_total' => '$' . $campaign_total, + ); + $this->push( + 'checkout_campaign_type', + $data + ); + } } } From ea3b16c9a801d7eda7d6400834808990dc7ec705 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Mon, 15 Apr 2024 19:39:19 +0530 Subject: [PATCH 5/8] Lint fixes --- includes/Listeners/WonderCart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 43dc4b7..6cad7b8 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -17,7 +17,7 @@ public function register_hooks() { add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); - add_action( 'woocommerce_checkout_order_processed', array( $this,'checkout_campaigns_used' ), 10, 1 ); + add_action( 'woocommerce_checkout_order_processed', array( $this, 'checkout_campaigns_used' ), 10, 1 ); } /** @@ -152,7 +152,7 @@ public function checkout_campaigns_used() { $campaign_total += $cart_item['yith_sales_discounts']['price_base'] - $cart_item['yith_sales_discounts']['price_adjusted']; } } - if( count( $campaigns ) > 0 ) { + if ( count( $campaigns ) > 0 ) { $data = array( 'label_key' => 'campaign_type', 'campaign_type' => array_unique( $campaigns ), From 78731f847f2c647a75fa4ba4e4a8af69d7610b89 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Mon, 15 Apr 2024 20:04:04 +0530 Subject: [PATCH 6/8] Corrected typo --- includes/Listeners/WonderCart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 6cad7b8..756ef3c 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -17,7 +17,7 @@ public function register_hooks() { add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); - add_action( 'woocommerce_checkout_order_processed', array( $this, 'checkout_campaigns_used' ), 10, 1 ); + add_action( 'woocommerce_checkout_order_processed', array( $this, 'checkout_campaigns_used' ), 10 ); } /** From ef57fb8d9d5af248fb81c9d7be7bcd2d76363ee2 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Wed, 24 Apr 2024 19:01:04 +0530 Subject: [PATCH 7/8] Updated the payment complete hook --- includes/Listeners/WonderCart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 756ef3c..2c3693d 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -17,7 +17,7 @@ public function register_hooks() { add_action( 'yith_sales_edit_campaign_event_modal_opened', array( $this, 'create_campaign_modal_open' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_selected', array( $this, 'campaign_selected' ), 10, 2 ); add_action( 'yith_sales_edit_campaign_event_campaign_abandoned', array( $this, 'campaign_abandoned' ), 10, 2 ); - add_action( 'woocommerce_checkout_order_processed', array( $this, 'checkout_campaigns_used' ), 10 ); + add_action( 'woocommerce_payment_complete', array( $this, 'checkout_campaigns_used' ) ); } /** From fa6f4e3aa869297c40002e57c95a37bce751d2d0 Mon Sep 17 00:00:00 2001 From: Mamatha Rao Date: Tue, 7 May 2024 16:52:34 +0530 Subject: [PATCH 8/8] Updated the keyword from 'campaign_type' to 'type' --- includes/Listeners/WonderCart.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php index 2c3693d..7be3efc 100644 --- a/includes/Listeners/WonderCart.php +++ b/includes/Listeners/WonderCart.php @@ -83,7 +83,7 @@ public function create_campaign_modal_open( $args, $event ) { public function campaign_selected( $args, $event ) { $data = array( 'label_key' => 'campaign_slug', - 'campaign_type' => $args['type'], + 'type' => $args['type'], 'campaign_slug' => $args['type'], ); @@ -105,7 +105,7 @@ public function campaign_selected( $args, $event ) { public function campaign_abandoned( $args, $event ) { $data = array( 'label_key' => 'campaign_slug', - 'campaign_type' => $args['type'], + 'type' => $args['type'], 'campaign_slug' => $args['type'] . '-' . $args['id'], ); @@ -154,8 +154,8 @@ public function checkout_campaigns_used() { } if ( count( $campaigns ) > 0 ) { $data = array( - 'label_key' => 'campaign_type', - 'campaign_type' => array_unique( $campaigns ), + 'label_key' => 'type', + 'type' => array_unique( $campaigns ), 'campaign_count' => count( $campaigns ), 'campaign_total' => '$' . $campaign_total, );