event_merge_tag_groups = array( 'aff_affiliate', 'aff_referral', 'bwf_contact' ); $this->event_name = esc_html__( 'Affiliate Makes A Sale', 'wp-marketing-automations-pro' ); $this->event_desc = esc_html__( 'This event runs after an affiliate makes a sale.', 'wp-marketing-automations-pro' ); $this->event_rule_groups = array( 'affiliatewp', 'bwf_contact_segments', 'bwf_contact', 'bwf_contact_fields', 'bwf_contact_user', 'bwf_contact_wc', 'bwf_contact_geo', 'bwf_engagement', 'bwf_broadcast' ); $this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' ); $this->priority = 40; $this->customer_email_tag = '{{affwp_affiliate_email}}'; $this->v2 = true; } public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } public function load_hooks() { add_action( 'affwp_set_referral_status', [ $this, 'process' ], 10, 3 ); } /** * Make the required data for the current event and send it asynchronously. * * @param $referral_id * @param $new_status * @param $old_status */ public function process( $referral_id, $new_status, $old_status ) { if ( 'unpaid' !== $new_status || $old_status === $new_status ) { return; } $data = $this->get_default_data(); $data['referral_id'] = $referral_id; $data['old_status'] = $old_status; $this->send_async_call( $data ); } /** * Set up rules data * * @param $automation_data */ public function pre_executable_actions( $automation_data ) { BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' ); BWFAN_Core()->rules->setRulesData( $this->referral_id, 'referral_id' ); BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' ); } /** * Registers the tasks for current event. * * @param $automation_id * @param $integration_data * @param $event_data */ public function register_tasks( $automation_id, $integration_data, $event_data ) { if ( ! is_array( $integration_data ) ) { return; } $data_to_send = $this->get_event_data(); $this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send ); } public function get_event_data() { $data_to_send = [ 'global' => [] ]; $data_to_send['global']['referral_id'] = $this->referral_id; $data_to_send['global']['affiliate_id'] = $this->affiliate_id; $data_to_send['global']['old_status'] = $this->old_status; $data_to_send['global']['user_id'] = $this->user_id; return $data_to_send; } /** * Make the view data for the current event which will be shown in task listing screen. * * @param $global_data * * @return false|string */ public function get_task_view( $global_data ) { ob_start(); $affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0; ?>