/** * 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) { if ($queue_item->order_id && $queue_item->product_id) { $order = WC_FUE_Compatibility::wc_get_order($queue_item->order_id); $item_id = $queue_item->product_id; // booking data $meta = maybe_unserialize($queue_item->meta); $booking_id = !empty($meta['booking_id']) ? $meta['booking_id'] : 0; if ($booking_id == 0) { return $variables; } /** * @var $booking WC_Booking * @var $booking_product WC_Product_Booking */ $booking = get_wc_booking($booking_id); $booking_product = $booking->get_product(); $booking_duration = $this->duration_to_string($booking_product->get_duration(), $booking_product->get_duration_unit()); $booking_date = $booking->get_start_date(get_option('date_format'), ''); $booking_time = $booking->get_start_date('', get_option('time_format')); $booking_amount = woocommerce_price($booking->cost); $booking_persons = ''; $booking_resource = $booking->resource_id > 0 ? get_the_title($booking->resource_id) : ''; if ($booking->has_persons()) { $booking_persons = '<ul>'; foreach ($booking->get_persons() as $person_id => $num) { $booking_persons .= '<li>' . get_the_title($person_id) . ': ' . $num . '</li>'; } $booking_persons .= '</ul>'; } $used_cats = array(); $item_cats = '<ul>'; $categories = get_the_terms($booking->product_id, 'product_cat'); if (is_array($categories)) { foreach ($categories as $category) { if (!in_array($category->term_id, $used_cats)) { $item_cats .= apply_filters('fue_email_cat_list', '<li>' . $category->name . '</li>', $queue_item->id, $categories); $used_cats[] = $category->term_id; } } } $variables['item_name'] = FUE_Addon_Woocommerce::get_product_name($booking_product); $variables['item_category'] = $item_cats; $variables['booking_duration'] = $booking_duration; $variables['booking_date'] = $booking_date; $variables['booking_time'] = $booking_time; $variables['booking_amount'] = $booking_amount; $variables['booking_resource'] = $booking_resource; $variables['booking_persons'] = $booking_persons; $variables['order_billing_address'] = $order->get_formatted_billing_address(); $variables['order_shipping_address'] = $order->get_formatted_shipping_address(); } return $variables; }
/** * Get replacement data for test emails * * @param array $email_data * @param FUE_Email $email * * @return array */ private function get_test_replacement_data($email_data, $email) { $email_type = $email->type; $order_date = ''; $order_datetime = ''; $order_id = $email_data['order_id']; $product_id = $email_data['product_id']; $categories = ''; $replacements = array(); if ($email_type == 'storewide') { // check if user wants to simulate email from a specific order if (!empty($order_id)) { // make sure the order exist $order = WC_FUE_Compatibility::wc_get_order($order_id); if (!$order->id) { die(__('The Order ID does not exist. Please try again.')); } $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)); $order_id = apply_filters('woocommerce_order_number', $order->id, $order); $order_total = $this->get_plain_order_total($order); $billing_address = $order->get_formatted_billing_address(); $shipping_address = $order->get_formatted_shipping_address(); $used_cats = array(); $item_list = '<ul>'; $item_cats = '<ul>'; $items = $order->get_items(); $items_array = array(); foreach ($items as $item) { $item_id = isset($item['product_id']) ? $item['product_id'] : $item['id']; $item_name = FUE_Addon_Woocommerce::get_product_name($item_id); $items_array[] = $item_name; $item_list .= '<li><a href="' . get_permalink($item_id) . '">' . $item_name . '</a></li>'; $cats = get_the_terms($item_id, 'product_cat'); if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { if (!in_array($cat->term_id, $used_cats)) { $item_cats .= '<li>' . $cat->name . '</li>'; } } } } $item_list .= '</ul>'; $item_cats .= '</ul>'; $item_list_csv = implode(', ', $items_array); $customer_first = $order->billing_first_name; $customer_last = $order->billing_last_name; $customer_email = $order->billing_email; } else { $order_id = '798'; $order_total = function_exists('wc_price') ? wc_price(121.4) : woocommerce_price(121.4); $order_total = strip_tags($order_total); // check if user wants to simulate email from a specific order if (!empty($product_id)) { $item = WC_FUE_Compatibility::wc_get_product($product_id); $cats = get_the_terms($item->id, 'product_cat'); $item_url = get_permalink($item->id); $product_name = FUE_Addon_Woocommerce::get_product_name($product_id); $item_name = '<a href="' . $item_url . '">' . $product_name . '</a>'; $item_price = strip_tags($item->get_price_html()); $item_qty = 1; $item_list = '<ul><li>' . $item_name . '</li></ul>'; $item_cats = '<ul>'; $item_list_csv = $product_name; if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { $item_cats .= '<li>' . $cat->name . '</li>'; } } $item_cats .= '</ul>'; } else { $item_list = '<ul><li><a href="#">Item 1</a></li><li><a href="#">Item 2</a></li></ul>'; $item_cats = '<ul><li>Category 1</li><li>Category 2</li></ul>'; $item_list_csv = 'Item 1, Item 2'; $item_price = ''; $item_qty = ''; } $billing_address = '77 North Beach Dr., Miami, FL 35122'; $shipping_address = '77 North Beach Dr., Miami, FL 35122'; $customer_first = $email_data['first_name']; $customer_last = $email_data['last_name']; $customer_email = $email_data['email_to']; $replacements['item_price'] = $item_price; $replacements['item_quantity'] = $item_qty; } $replacements['order_number'] = $order_id; $replacements['order_date'] = $order_date; $replacements['order_datetime'] = $order_datetime; $replacements['order_billing_address'] = $billing_address; $replacements['order_shipping_address'] = $shipping_address; $replacements['dollars_spent_order'] = $order_total; $replacements['customer_first_name'] = $customer_first; $replacements['customer_last_name'] = $customer_last; $replacements['customer_name'] = $customer_first . ' ' . $customer_last; $replacements['customer_email'] = $customer_email; $replacements['item_name'] = $item_list; $replacements['item_names'] = $item_list; $replacements['item_names_list'] = $item_list_csv; $replacements['item_categories'] = $item_cats; $replacements['item_category'] = $item_cats; } elseif ($email_type == 'reminder') { $categories = ''; $order_id = !empty($order_id) ? $order_id : '1100'; $order_total = function_exists('wc_price') ? wc_price(121.4) : woocommerce_price(121.4); $order_total = strip_tags($order_total); $order_date = date(get_option('date_format')); $order_datetime = date(get_option('date_format') . ' ' . get_option('time_format')); $billing_address = '77 North Beach Dr., Miami, FL 35122'; $shipping_address = '77 North Beach Dr., Miami, FL 35122'; $customer_first = 'John'; $customer_last = 'Doe'; $customer_email = '*****@*****.**'; if ($order_id != '1100' && ($order = WC_FUE_Compatibility::wc_get_order($order_id))) { $order_id = apply_filters('woocommerce_order_number', $order->id, $order); $order_total = $this->get_plain_order_total($order); $used_cats = array(); $item_list = '<ul>'; $item_cats = '<ul>'; $items = $order->get_items(); $items_array = array(); foreach ($items as $item) { $item_id = isset($item['product_id']) ? $item['product_id'] : $item['id']; $item_name = FUE_Addon_Woocommerce::get_product_name($item_id); $item_list .= '<li><a href="' . get_permalink($item_id) . '">' . $item_name . '</a></li>'; $cats = get_the_terms($item_id, 'product_cat'); if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { if (!in_array($cat->term_id, $used_cats)) { $item_cats .= '<li>' . $cat->name . '</li>'; } } } } $item_list .= '</ul>'; $item_cats .= '</ul>'; $item_list_csv = implode(', ', $items_array); } // check if user wants to simulate email from a specific order if (isset($email_data['product_id']) && !empty($email_data['product_id'])) { $item = WC_FUE_Compatibility::wc_get_product($email_data['product_id']); $cats = get_the_terms($item->id, 'product_cat'); if (is_array($cats) && !empty($cats)) { foreach ($cats as $cat) { $categories .= $cat->name . ', '; } $categories = rtrim($categories, ', '); } $item_name = $item->get_title(); $item_url = get_permalink($item->id); } else { $item_name = '<a href="#">Name of Product</a>'; $categories = 'Test Category'; $item_url = get_bloginfo('url'); } $replacements['order_number'] = $order_id; $replacements['dollars_spent_order'] = $order_total; $replacements['order_date'] = $order_date; $replacements['order_datetime'] = $order_datetime; $replacements['order_billing_address'] = $billing_address; $replacements['order_shipping_address'] = $shipping_address; $replacements['customer_first_name'] = $customer_first; $replacements['customer_last_name'] = $customer_last; $replacements['customer_name'] = $customer_first . ' ' . $customer_last; $replacements['customer_email'] = $customer_email; $replacements['item_name'] = '<a href="' . $item_url . '">' . $item_name . '</a>'; $replacements['item_names'] = $item_list; $replacements['item_names_list'] = $item_list_csv; $replacements['item_categories'] = $categories; $replacements['item_category'] = $categories; } else { $order_number = '1100'; $order_date = date(get_option('date_format')); $order_datetime = date(get_option('date_format') . ' ' . get_option('time_format')); $customer_first = 'John'; $customer_last = 'John Doe'; $customer_email = '*****@*****.**'; $billing_address = '77 North Beach Dr., Miami, FL 35122'; $shipping_address = '77 North Beach Dr., Miami, FL 35122'; $item_list = '<ul><li><a href="#">Item 1</a></li><li><a href="#">Item 2</a></li></ul>'; $item_list_csv = 'Item 1, Item 2'; $item_cats = '<ul><li>Category 1</li><li>Category 2</li></ul>'; $spent_order = strip_tags(woocommerce_price(19.99)); $spent_total = strip_tags(woocommerce_price(3250)); $total_orders = 12; $last_order_date = $order_date; $item_name = '<a href="#">Name of Product</a>'; $item_cat = 'Test Category'; $item_price = '$29.95'; $item_qty = 1; $replacements['order_number'] = $order_number; $replacements['order_date'] = $order_date; $replacements['order_datetime'] = $order_datetime; $replacements['customer_first_name'] = $customer_first; $replacements['customer_last_name'] = $customer_last; $replacements['customer_name'] = $customer_first . ' ' . $customer_last; $replacements['customer_email'] = $customer_email; $replacements['item_name'] = $item_name; $replacements['item_names'] = $item_list; $replacements['item_names_list'] = $item_list_csv; $replacements['item_category'] = $item_cat; $replacements['item_categories'] = $item_cat; $replacements['item_price'] = $item_price; $replacements['item_quantity'] = $item_qty; $replacements['amount_spent_order'] = $spent_order; $replacements['amount_spent_total'] = $spent_total; $replacements['number_orders'] = $total_orders; $replacements['last_purchase_date'] = $last_order_date; $replacements['order_billing_address'] = $billing_address; $replacements['order_shipping_address'] = $shipping_address; } return $replacements; }