Skip to content

Commit

Permalink
Updated hook to trigger only when the order is processed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mamatharao05 committed Apr 15, 2024
1 parent dbb29ff commit 1eebdee
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions includes/Listeners/WonderCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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
);
}
}
}

0 comments on commit 1eebdee

Please sign in to comment.