public function replace_variables($text, $email_order) { global $wc_points_rewards; $event_data = get_option('fue_email_order_' . $email_order->id, false); if (!$event_data) { $event_data = array('user_id' => 0, 'points' => 0, 'event_type' => ''); } $points = $event_data['points']; $points_label = $wc_points_rewards->get_points_label($points); $description = WC_Points_Rewards_Manager::event_type_description($event_data['event_type']); $search = array('{points_earned}', '{reward_event_description}'); $replacements = array($points, $description); return str_replace($search, $replacements, $text); }
/** * Gets point log entries based on $args * * @since 1.0 * @param array $args the query arguments * @return array of log entry objects */ public static function get_points_log_entries($args) { global $wc_points_rewards, $wpdb; // special handling for searching by user if (!empty($args['user'])) { $args['where'][] = $wpdb->prepare("{$wc_points_rewards->user_points_log_db_tablename}.user_id = %s", $args['user']); } // special handling for searching by event type if (!empty($args['event_type'])) { $args['where'][] = $wpdb->prepare("{$wc_points_rewards->user_points_log_db_tablename}.type = %s", $args['event_type']); } $entries = array(); foreach (self::query($args) as $log_entry) { // maybe unserialize the arbitrary data object $log_entry->data = maybe_unserialize($log_entry->data); // Format the event date as "15 minutes ago" if the event took place in the last 24 hours, otherwise just show the date (timestamp on mouse hover) $timestamp = strtotime($log_entry->date); $t_time = date_i18n('Y/m/d g:i:s A', $timestamp); $time_diff = current_time('timestamp', true) - $timestamp; if ($time_diff > 0 && $time_diff < 24 * 60 * 60) { $h_time = sprintf(__('%s ago', 'wc_points_rewards'), human_time_diff($timestamp, current_time('timestamp', true))); } else { $h_time = date_i18n(woocommerce_date_format(), $timestamp); } $log_entry->date_display_human = $h_time; $log_entry->date_display = $t_time; // retrieve the description $log_entry->description = WC_Points_Rewards_Manager::event_type_description($log_entry->type, $log_entry); $entries[] = $log_entry; } return $entries; }
public function replace_variables($text, $email_order) { global $wc_points_rewards; $event_data = get_option('fue_email_order_' . $email_order->id, false); if (!$event_data) { $event_data = array('user_id' => 0, 'points' => 0, 'event_type' => ''); } $points = $event_data['points']; $points_label = $wc_points_rewards->get_points_label($points); $description = WC_Points_Rewards_Manager::event_type_description($event_data['event_type']); $search = array('{order_number}', '{order_date}', '{order_datetime}', '{customer_first_name}', '{customer_name}', '{customer_email}', '{points_earned}', '{reward_event_description}'); if ($email_order->order_id > 0) { $order = new WC_Order($email_order->order_id); $order_number = $order->get_order_number(); $order_date = date(get_option('date_format'), strtotime($order->order_date)); $order_datetime = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date)); $first_name = $order->billing_first_name; $name = $order->billing_first_name . ' ' . $order->billing_last_name; $email = $order->billing_email; } else { $user = new WP_User($email_order->user_id); $order_number = ''; $order_date = ''; $order_datetime = ''; $first_name = $user->first_name; $name = $user->first_name . ' ' . $user->last_name; $email = $user->user_email; } $replacements = array($order_number, $order_date, $order_datetime, $first_name, $name, $email, $points, $description); return str_replace($search, $replacements, $text); }
/** * Scan through the keys of $variables and apply the replacement if one is found * @param array $variables * @param array $email_data * @param object $queue_item * @param FUE_Email $email * @return array */ protected function add_variable_replacements($variables, $email_data, $queue_item, $email) { $event_data = get_option('fue_email_order_' . $queue_item->id, false); if (!$event_data) { $event_data = array('user_id' => 0, 'points' => 0, 'event_type' => ''); } $points = $event_data['points']; $description = WC_Points_Rewards_Manager::event_type_description($event_data['event_type']); $variables['points_earned'] = $points; $variables['reward_event_description'] = $description; return $variables; }