aign_name = ''; if(isset($data['campaign_id']) && !empty($data['campaign_id'])){ $campaign_model = new EarnCampaign(); $campaign = $campaign_model->getByKey($data['campaign_id']); $campaign_name = !empty($campaign) && isset($campaign->name) && !empty($campaign->name) ? $campaign->name: ''; } $user_points = isset($loyal_user) && is_object($loyal_user) && isset($loyal_user->points) && $loyal_user->points > 0 ? $loyal_user->points: 0; $total_earned_point = isset($loyal_user) && is_object($loyal_user) && isset($loyal_user->earn_total_point) && $loyal_user->earn_total_point > 0 ? $loyal_user->earn_total_point: 0; $used_points = isset($loyal_user) && is_object($loyal_user) && isset($loyal_user->used_total_points) && $loyal_user->used_total_points > 0 ? $loyal_user->used_total_points: 0; $short_codes = array( '{wlr_campaign_name}' => $campaign_name, '{wlr_action_name}' => $reward_helper->getActionName($action_type), '{wlr_earn_reward}' => $display_name, '{wlr_referral_url}' => $referral_url, '{wlr_user_point}' => $user_points, '{wlr_total_earned_point}' => $total_earned_point, '{wlr_used_point}' => $used_points, '{wlr_user_name}' => $this->getUserDisplayName($email), '{wlr_order_id}' => isset($data['order_id']) && !empty($data['order_id']) ? $data['order_id']: "" ); $short_codes = apply_filters('wlr_earn_reward_email_short_codes', $short_codes); $content = stripslashes(get_option('wlr_earn_reward_email_template')); $content_html = empty($content) ? $this->defaultContent() : $content; foreach ($short_codes as $short_code => $short_code_value) { $content_html = str_replace($short_code,$short_code_value,$content_html); $this->add_placeholder($short_code, $short_code_value); } $this->add_placeholder('{wlr_earn_reward_mail_content}', $content_html); $subject = $this->get_subject(); $attachments = $this->get_attachments(); if (empty($attachments)) { $attachments = array(); } if ($this->is_enabled()) { $created_at = strtotime(date("Y-m-d h:i:s")); $log_data = array( 'user_email' => sanitize_email($email), 'action_type' => $action_type, 'earn_campaign_id' => 0, 'campaign_id' => isset($data['campaign_id']) && !empty($data['campaign_id']) ? $data['campaign_id']:0, 'order_id' => isset($data['order_id']) && !empty($data['order_id']) ? $data['order_id']:0, 'product_id' => isset($data['product_id']) && !empty($data['product_id']) ? $data['product_id']:0, 'admin_id' => isset($data['admin_id']) && !empty($data['admin_id']) ? $data['admin_id']:0, 'created_at' => $created_at, 'modified_at' => 0, 'points' => 0, 'action_process_type' => 'email_notification', 'referral_type' => '', 'reward_id' => isset($data['reward_id']) && !empty($data['reward_id']) ? $data['reward_id']:0, 'user_reward_id' => isset($data['user_reward_id']) && !empty($data['user_reward_id']) ? $data['user_reward_id']:0, 'expire_email_date' => 0, 'expire_date' => 0, 'reward_display_name' => $display_name, 'required_points' => 0, 'discount_code' => null, ); $reward_label = $reward_helper->getRewardLabel(1); $log_data['note'] = sprintf(__('Sending earned %s email failed(%s)','wp-loyalty-rules'),$reward_label,$campaign_name); $log_data['customer_note'] = sprintf(__('Sending earned %s email failed to %s for %s campaign','wp-loyalty-rules'),$reward_label,$email,$campaign_name); if($this->send($this->get_recipient(), $subject, $this->get_content(), $this->get_headers(), $attachments)){ $log_data['note'] = sprintf(__('Earned %s email sent to customer successfully(%s)','wp-loyalty-rules'),$reward_label,$campaign_name); $log_data['customer_note'] = sprintf(__('Earned %s email sent to %s for %s campaign','wp-loyalty-rules'),$reward_label,$email,$campaign_name); } $reward_helper->add_note($log_data); } } } /** * Add placeholder * @param $find * @param $replace */ function add_placeholder($find, $replace) { $index = array_search($find, $this->find, true); if ($index === false) { $this->find[] = $find; $this->replace[] = $replace; } else { $this->find[$index] = $find; $this->replace[$index] = $replace; } self::$replace_place_array[$find] = $replace; } /** * get_content_html function. * * @access public * @return string */ function get_content_html() { self::$replace_place_array['email'] = $this; ob_start(); wc_get_template($this->template_html, self::$replace_place_array, '', $this->template_base); $html = ob_get_clean(); return $this->format_string($html); } /** * get_content_plain function. * * @access public * @return string */ function get_content_plain() { self::$replace_place_array['email'] = $this; ob_start(); wc_get_template($this->template_plain, self::$replace_place_array, '', $this->template_base); $html = ob_get_clean(); return $this->format_string($html); } function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __('Enable/Disable', 'wp-loyalty-rules'), 'type' => 'checkbox', 'label' => __('Enable this email notification', 'wp-loyalty-rules'), 'default' => 'yes', ), 'subject' => array( 'title' => __('Subject', 'wp-loyalty-rules'), 'type' => 'text', 'description' => sprintf(__('This controls the email subject line. Leave blank to use the default subject: %s.', 'wp-loyalty-rules'), $this->subject), 'placeholder' => '', 'default' => $this->default_subject ), 'heading' => array( 'title' => __('Email Heading', 'wp-loyalty-rules'), 'type' => 'text', 'description' => sprintf(__('This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'wp-loyalty-rules'), $this->heading), 'placeholder' => '', 'default' => $this->default_heading ), 'email_type' => array( 'title' => __('Email type', 'wp-loyalty-rules'), 'type' => 'select', 'description' => __('Choose which format of email to send.', 'wp-loyalty-rules'), 'default' => 'html', 'class' => 'email_type', 'options' => array( 'plain' => __('Plain text', 'wp-loyalty-rules'), 'html' => __('HTML', 'wp-loyalty-rules'), 'multipart' => __('Multipart', 'wp-loyalty-rules'), ) ) ); } }