public function __construct($order_id = 0) { $this->order_id = $order_id; $this->order = new WC_Order($this->order_id); $wc_emails = new WC_Emails(); $this->emails = $wc_emails->get_emails(); }
function run_email_script() { // assign email address and order id variables if (get_option("wc_email_test_email", false)) { $wc_email_test_email = get_option("wc_email_test_email", false); } else { $wc_email_test_email = get_bloginfo('admin_email'); } if (get_option("wc_email_test_order_id", false) == 'recent') { $wc_email_test_order_id = ''; } else { $wc_email_test_order_id = get_option("wc_email_test_order_id", false); } if (!$wc_email_test_order_id) { // get a valid and most recent order_id ( if no order is has been selected ) global $wpdb; $order_id_query = 'SELECT order_id FROM ' . $wpdb->prefix . 'woocommerce_order_items ORDER BY order_item_id DESC LIMIT 1'; $order_id = $wpdb->get_results($order_id_query); if (empty($order_id)) { echo "No order within your WooCommerce shop. Please create a test order first to test the emails"; return; } else { $wc_email_test_order_id = $order_id[0]->order_id; } } // the email type to send $email_class = get_query_var('woocommerce_email_test'); $for_filter = strtolower(str_replace('WC_Email_', '', $email_class)); // change email address within order to saved option add_filter('woocommerce_email_recipient_' . $for_filter, 'your_email_recipient_filter_function', 10, 2); function your_email_recipient_filter_function($recipient, $object) { global $wc_email_test_email; $recipient = $wc_email_test_email; return $recipient; } // change subject link add_filter('woocommerce_email_subject_' . $for_filter, 'change_admin_email_subject', 1, 2); function change_admin_email_subject($subject, $order) { global $woocommerce; $subject = "TEST EMAIL: " . $subject; return $subject; } if (isset($GLOBALS['wc_advanced_notifications'])) { unset($GLOBALS['wc_advanced_notifications']); } // load the email classs $wc_emails = new WC_Emails(); $emails = $wc_emails->get_emails(); // select the email we want & send $new_email = $emails[$email_class]; // make sure email isn't sent apply_filters('woocommerce_email_enabled_' . $for_filter, false, $new_email->object); $new_email->trigger($wc_email_test_order_id); // echo the email content for browser echo $new_email->style_inline($new_email->get_content()); }
public function trigger($recipient, $subject, $content, $attachment = array()) { /* global $woocommerce; */ $mail = new WC_Emails(); $email_heading = get_bloginfo('name'); ob_start(); $mail->email_header($email_heading); $message = ob_get_clean(); $message .= $content; ob_start(); $mail->email_footer(); $message .= ob_get_clean(); $mail->send($recipient, $subject, $message, "Content-Type: text/html\r\n", $attachment); }
/** * Prepares and send the review request mail * * @since 1.0.0 * @param $order_id int the order id * @param $days * @param $items_to_review * @param $stored_items * @return void * @author Alberto Ruggiero */ static function send_email($order_id, $days, $items_to_review = array(), $stored_items = array()) { $list = YWRR_Emails::get_review_list($order_id); $wc_email = WC_Emails::instance(); $email = $wc_email->emails['YWRR_Request_Mail']; $email->trigger($order_id, $list, $days); }
/** * Send a test mail from option panel * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function send_test_mail() { ob_start(); $total_products = wp_count_posts('product'); if (!$total_products->publish) { wp_send_json(array('error' => __('In order to send the test email, at least one product has to be published', 'yith-woocommerce-review-reminder'))); } else { $args = array('posts_per_page' => 2, 'orderby' => 'rand', 'post_type' => 'product'); $random_products = get_posts($args); $test_items = array(); foreach ($random_products as $item) { $test_items[$item->ID]['id'] = $item->ID; $test_items[$item->ID]['name'] = $item->post_title; } $days = get_option('ywrr_mail_schedule_day'); $test_email = $_POST['email']; $template = $_POST['template']; try { $wc_email = WC_Emails::instance(); $email = $wc_email->emails['YWRR_Request_Mail']; $email_result = $email->trigger(0, $test_items, $days, $test_email, $template); if (!$email_result) { wp_send_json(array('error' => __('There was an error while sending the email', 'yith-woocommerce-review-reminder'))); } else { wp_send_json(true); } } catch (Exception $e) { wp_send_json(array('error' => $e->getMessage())); } } }
/** * Main WC_Emails Instance. * * Ensures only one instance of WC_Emails is loaded or can be loaded. * * @since 2.1 * @static * @return WC_Emails Main instance */ public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Render the settings for the current section * * @since 2.0.0 */ public function output() { $settings = $this->get_settings(); // inject the actual setting value before outputting the fields // ::output_fields() uses get_option() but customizations are stored // in a single option so this dynamically returns the correct value if (isset($_GET['section']) && $_GET['section'] == 'email_options') { // email options $wc_emails = (array) WC_Emails::instance()->emails; foreach (self::$wc_emails_enabled as $filed => $id) { $email_enabled = (array) $wc_emails[$filed]; if ($email_enabled['enabled'] == 'no') { add_filter("pre_option_{$filed}", function () { return 'no'; }); } else { add_filter("pre_option_{$filed}", function () { return 'yes'; }); } } } if (isset($_GET['section']) && $_GET['section'] == 'sms_options') { } foreach ($this->customizations as $filter => $value) { add_filter("pre_option_{$filter}", array($this, 'get_customization')); } WC_Admin_Settings::output_fields($settings); }
public function load() { if (class_exists('WC_Emails')) { $wc_emails = WC_Emails::instance(); $emails = $wc_emails->get_emails(); if (!empty($emails)) { $this->emails = $emails; } } }
/** * Save settings. */ public function save() { global $current_section; if (!$current_section) { WC_Admin_Settings::save_fields($this->get_settings()); } else { $wc_emails = WC_Emails::instance(); if (in_array($current_section, array_map('sanitize_title', array_keys($wc_emails->get_emails())))) { foreach ($wc_emails->get_emails() as $email_id => $email) { if ($current_section === sanitize_title($email_id)) { do_action('woocommerce_update_options_' . $this->id . '_' . $email->id); } } } else { do_action('woocommerce_update_options_' . $this->id . '_' . $current_section); } } }
/** * Prepares and send the review request mail * * @since 1.0.0 * * @param $order_id int the order id * @param $days * @param $items_to_review * @param $stored_items * * @return void * @author Alberto Ruggiero */ public function send_email($order_id, $days, $items_to_review = array(), $stored_items = array()) { if (defined('YWRR_PREMIUM')) { if (empty($stored_items)) { if (empty($items_to_review)) { $list = YWRR_Emails_Premium()->get_review_list($order_id); } else { $list = YWRR_Emails_Premium()->get_review_list_forced($items_to_review, $order_id); } } else { $list = $stored_items; } } else { $list = $this->get_review_list($order_id); } $wc_email = WC_Emails::instance(); $email = $wc_email->emails['YWRR_Request_Mail']; $email->trigger($order_id, $list, $days); }
/** * Handles the unsubscribe form * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function unsubscribe_review_request() { if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } if (empty($_POST['action']) || 'unsubscribe_review_request' !== $_POST['action'] || empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'unsubscribe_review_request')) { return; } $customer_email = !empty($_POST['account_email']) ? sanitize_email($_POST['account_email']) : ''; if (empty($customer_email) || !is_email($customer_email)) { wc_add_notice(__('Please provide a valid email address.', 'yith-woocommerce-review-reminder'), 'error'); } elseif ($customer_email !== urldecode(base64_decode($_GET['email']))) { wc_add_notice(__('Please retype the email address as provided.', 'yith-woocommerce-review-reminder'), 'error'); } if (wc_notice_count('error') === 0) { $wc_email = WC_Emails::instance(); $email = $wc_email->emails['YWRR_Unsubscribe_Mail']; $email->trigger($customer_email); wc_add_notice(__('An email has been sent with your request', 'yith-woocommerce-review-reminder')); wp_safe_redirect(get_permalink(get_option('ywrr_unsubscribe_page_id'))); exit; } }
/** * Register WC settings from WP-API to the REST API. * @since 2.7.0 */ public function register_wp_admin_settings() { $pages = WC_Admin_Settings::get_settings_pages(); foreach ($pages as $page) { new WC_Register_WP_Admin_Settings($page, 'page'); } $emails = WC_Emails::instance(); foreach ($emails->get_emails() as $email) { new WC_Register_WP_Admin_Settings($email, 'email'); } }
/** * Sends an email when a partial payment is made */ public function payment_complete_handler($order_id) { $order = wc_get_order($order_id); if ('wc-partial-payment' !== $order->post_status) { return; } $wc_emails = WC_Emails::instance(); $customer_email = $wc_emails->emails['WC_Email_Customer_Processing_Order']; $admin_email = $wc_emails->emails['WC_Email_New_Order']; $customer_email->trigger($order); $admin_email->trigger($order); }
/** * Send an email * * @param Email $email * @param string $recipient * * @return bool */ public function send(Email $email, $recipient) { $wc_emails = new \WC_Emails(); return $wc_emails->send($recipient, $email->get_subject(), $email->get_content()); }
public function addOfferNoteCallback() { if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) { $post_id = $_POST["targetID"]; // Get current data for Offer $post_data = get_post($post_id); // Filter Post Status Label $post_status_text = strtolower($post_data->post_status) == 'publish' ? 'Pending' : $post_data->post_status; $post_status_text = ucwords(str_replace("-", " ", str_replace("offer", " ", strtolower($post_status_text)))); $noteSendToBuyer = isset($_POST["noteSendToBuyer"]) && $_POST["noteSendToBuyer"] != '' ? '1' : ''; $offer_notes = $_POST['noteContent']; $current_user = wp_get_current_user(); // Insert WP comment $comment_text = "<span>" . __('Offer Note:', $this->plugin_slug) . "</span>"; if ($noteSendToBuyer != '1') { $comment_text .= " " . __('(admin only)', $this->plugin_slug); } else { $comment_text .= " " . __('(sent to buyer)', $this->plugin_slug); } $comment_text .= "<br />" . $offer_notes; $data = array('comment_post_ID' => '', 'comment_author' => $current_user->user_login, 'comment_author_email' => $current_user->user_email, 'comment_author_url' => '', 'comment_content' => $comment_text, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => get_current_user_id(), 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => '', 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'comment_approved' => 'post-trashed'); $new_comment_id = wp_insert_comment($data); // insert comment meta if ($new_comment_id) { add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true); } if ($new_comment_id) { if ($noteSendToBuyer == '1') { // Email buyer the offer note (not private admin note) /** * Offer note email template * @since 0.1.0 */ // set recipient email $recipient = get_post_meta($post_id, 'offer_email', true); $offer_id = $post_id; $offer_uid = get_post_meta($post_id, 'offer_uid', true); $offer_name = get_post_meta($post_id, 'offer_name', true); $offer_email = $recipient; $product_id = get_post_meta($post_id, 'offer_product_id', true); $variant_id = get_post_meta($post_id, 'offer_variation_id', true); $_pf = new WC_Product_Factory(); $product = $variant_id ? $_pf->get_product($variant_id) : $_pf->get_product($product_id); // if buyercountered-offer previous then use buyer counter values $is_offer_buyer_countered_status = $post_data->post_status == 'buyercountered-offer' ? true : false; $product_qty = $is_offer_buyer_countered_status ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true); $product_price_per = $is_offer_buyer_countered_status ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true); $product_total = $product_qty * $product_price_per; $offer_args = array('recipient' => $recipient, 'offer_email' => $offer_email, 'offer_name' => $offer_name, 'offer_id' => $offer_id, 'offer_uid' => $offer_uid, 'product_id' => $product_id, 'product_url' => $product->get_permalink(), 'variant_id' => $variant_id, 'product' => $product, 'product_qty' => $product_qty, 'product_price_per' => $product_price_per, 'product_total' => $product_total, 'offer_notes' => $offer_notes); if ($variant_id) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product->variation_id; } $attributes = $product->get_variation_attributes(); $extra_data = ' – ' . implode(', ', $attributes); $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'woocommerce'), $identifier, $product->get_title(), $extra_data); } else { $offer_args['product_title_formatted'] = $product->get_formatted_name(); } // the email we want to send $email_class = 'WC_Offer_Note_Email'; // load the WooCommerce Emails $wc_emails = new WC_Emails(); $emails = $wc_emails->get_emails(); // select the email we want & trigger it to send $new_email = $emails[$email_class]; $new_email->recipient = $recipient; // set plugin slug in email class $new_email->plugin_slug = $this->plugin_slug; // define email template/path (html) $new_email->template_html = 'woocommerce-offer-note.php'; $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/'; // define email template/path (plain) $new_email->template_plain = 'woocommerce-offer-note.php'; $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/'; $new_email->trigger($offer_args); } $redirect_url = admin_url('post.php?post=' . $post_id . '&action=edit&noheader=true&message=11'); echo $redirect_url; } else { echo 'failed'; } die; // this is required to return a proper result } }
protected static function _enable_emails() { self::_disable_emails(); $emails = WC_Emails::instance(); add_action('woocommerce_order_status_pending_to_processing_notification', array($emails->emails['WC_Email_Customer_Processing_Order'], 'trigger'), 10); add_action('woocommerce_order_status_pending_to_on-hold_notification', array($emails->emails['WC_Email_Customer_Processing_Order'], 'trigger'), 10); add_action('woocommerce_order_status_completed_notification', array($emails->emails['WC_Email_Customer_Completed_Order'], 'trigger'), 10); add_action('woocommerce_order_status_pending_to_processing_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); add_action('woocommerce_order_status_pending_to_completed_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); add_action('woocommerce_order_status_pending_to_on-hold_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); add_action('woocommerce_order_status_failed_to_processing_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); add_action('woocommerce_order_status_failed_to_completed_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); add_action('woocommerce_order_status_failed_to_on-hold_notification', array($emails->emails['WC_Email_New_Order'], 'trigger'), 10); }
/** * Needed to load email classes in admin to adjust optionsv and add additional hook */ public function handler_wc_init() { if( is_admin() ) { // fires wc_email_classes -> handler_wc_email_classes $wc_emails = WC_Emails::instance(); unset( $wc_emails ); } }
/** * Send an invoice for a scheduled order when the post date passes the current date */ public static function invoice_scheduled_orders() { global $wpdb; $mailer = WC_Emails::instance(); $date = date("Y-m-d H:i:s", current_time('timestamp')); $due_orders = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT \tposts.ID\n\t\t\tFROM \t{$wpdb->posts} AS posts\n\t\t\tWHERE \tposts.post_type = 'shop_order'\n\t\t\tAND \tposts.post_status = 'wc-scheduled-payment'\n\t\t\tAND \tposts.post_date < %s\n\t\t", $date)); if ($due_orders) { foreach ($due_orders as $due_order) { $order = wc_get_order($due_order); $order->update_status('pending', __('Scheduled order ready for payment.', 'woocommerce-deposits')); $mailer->customer_invoice($order); } } }
public function new_offer_form_submit() { if (!is_admin()) { global $wpdb; // this is how you get access to the database // Check if form was posted and select task accordingly if (isset($_REQUEST['woocommerceoffer_post']) && isset($_POST["offer_product_id"]) && $_POST["offer_product_id"] != '') { // set postmeta original vars $formData['orig_offer_name'] = isset($_POST['offer_name']) ? $_POST['offer_name'] : ''; $formData['orig_offer_company_name'] = isset($_POST['offer_company_name']) ? $_POST['offer_company_name'] : ''; $formData['orig_offer_phone'] = isset($_POST['offer_phone']) ? $_POST['offer_phone'] : ''; $formData['orig_offer_email'] = isset($_POST['offer_email']) ? $_POST['offer_email'] : ''; $formData['orig_offer_product_id'] = isset($_POST['offer_product_id']) ? $_POST['offer_product_id'] : ''; $formData['orig_offer_variation_id'] = isset($_POST['offer_variation_id']) ? $_POST['offer_variation_id'] : ''; $formData['orig_offer_quantity'] = isset($_POST['offer_quantity']) ? $_POST['offer_quantity'] : '0'; $formData['orig_offer_price_per'] = isset($_POST['offer_price_each']) ? $_POST['offer_price_each'] : '0'; $formData['orig_offer_amount'] = number_format(round($formData['orig_offer_quantity'] * $formData['orig_offer_price_per']), 2, ".", ""); $formData['orig_offer_uid'] = uniqid('aewco-'); $formData['parent_offer_uid'] = isset($_POST['parent_offer_uid']) ? $_POST['parent_offer_uid'] : ''; /** * Check minimum quantity and minimum price */ // check for valid offer quantity (not zero) if ($formData['orig_offer_quantity'] == '' || $formData['orig_offer_quantity'] == 0) { echo json_encode(array("statusmsg" => 'failed-custom', "statusmsgDetail" => __('Please enter a positive value for \'Offer Quantity\'', $this->plugin_slug))); exit; } // check for valid offer price (not zero) if ($formData['orig_offer_price_per'] == '' || $formData['orig_offer_price_per'] == 0 || $formData['orig_offer_price_per'] == "0.00") { echo json_encode(array("statusmsg" => 'failed-custom', "statusmsgDetail" => __('Please enter a positive value for \'Offer Amount\'', $this->plugin_slug))); exit; } // set postmeta vars $formData['offer_name'] = $formData['orig_offer_name']; $formData['offer_company_name'] = $formData['orig_offer_company_name']; $formData['offer_phone'] = $formData['orig_offer_phone']; $formData['offer_email'] = $formData['orig_offer_email']; $formData['offer_product_id'] = $formData['orig_offer_product_id']; $formData['offer_variation_id'] = $formData['orig_offer_variation_id']; $formData['offer_quantity'] = $formData['orig_offer_quantity']; $formData['offer_price_per'] = $formData['orig_offer_price_per']; $formData['offer_amount'] = $formData['orig_offer_amount']; $formData['offer_uid'] = $formData['orig_offer_uid']; // if not logged in, check for matching wp user by email // set author_data $author_data = !is_user_logged_in() ? get_user_by('email', $formData['offer_email']) : false; if ($author_data) { $newPostData['post_author'] = $author_data->ID; } // set post vars $newPostData['post_date'] = date("Y-m-d H:i:s", current_time('timestamp', 0)); $newPostData['post_date_gmt'] = gmdate("Y-m-d H:i:s", time()); $newPostData['post_type'] = 'woocommerce_offer'; $newPostData['post_status'] = 'publish'; $newPostData['post_title'] = $formData['offer_email']; // set offer comments $comments = isset($_POST['offer_notes']) && $_POST['offer_notes'] != '' ? strip_tags(nl2br($_POST['offer_notes']), '<br><p>') : ''; /** * Akismet spam check * Passes back true (it's spam) or false (it's ham) * @since 1.2.0 */ $akismet_api_key = '9a57112207be'; $data = array('blog' => get_site_url(), 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => '', 'permalink' => get_permalink($formData['offer_product_id']), 'comment_type' => 'woocommerce_offer', 'comment_author' => $formData['offer_name'], 'comment_author_email' => $formData['offer_email'], 'comment_author_url' => '', 'comment_content' => $comments); if ($this->aeofwc_akismet_comment_check($akismet_api_key, $data)) { // is spam echo json_encode(array("statusmsg" => 'failed-spam', "statusmsgDetail" => __('Invalid Offer Submission; See shop manager for assistance', $this->plugin_slug))); exit; } // check for parent post id $parent_post_id = isset($_POST['parent_offer_id']) ? $_POST['parent_offer_id'] : ''; $parent_post_status = get_post_status($parent_post_id); $post_parent_type = get_post_type($parent_post_id); // If has valid parent offer id post $is_counter_offer = $parent_post_id != '' ? true : false; if ($is_counter_offer) { // check for parent offer unique id $parent_post_offer_uid = get_post_meta($parent_post_id, 'offer_uid', true); // check for valid parent offer ( must be a offer post type and accepted/countered and uid must match if (isset($parent_post_status) && $parent_post_status != 'countered-offer' || $post_parent_type != 'woocommerce_offer' || $parent_post_offer_uid != $formData['parent_offer_uid']) { echo json_encode(array("statusmsg" => 'failed-custom', "statusmsgDetail" => __('Invalid Parent Offer Id; See shop manager for assistance', $this->plugin_slug))); exit; } $parent_post = array('ID' => $parent_post_id, 'post_modified' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'post_modified_gmt' => gmdate("Y-m-d H:i:s", current_time('timestamp', 0)), 'post_status' => 'buyercountered-offer'); if ($author_data) { $parent_post['post_author'] = $newPostData['post_author']; } // Update the parent post into the database wp_update_post($parent_post); $formDataUpdated = array(); $formDataUpdated['offer_buyer_counter_quantity'] = $formData['offer_quantity']; $formDataUpdated['offer_buyer_counter_price_per'] = $formData['offer_price_per']; $formDataUpdated['offer_buyer_counter_amount'] = $formData['offer_amount']; // Insert new Post Meta Values foreach ($formDataUpdated as $k => $v) { $newPostMetaData = array(); $newPostMetaData['post_id'] = $parent_post_id; $newPostMetaData['meta_key'] = $k; $newPostMetaData['meta_value'] = $v; update_post_meta($parent_post_id, $newPostMetaData['meta_key'], $newPostMetaData['meta_value']); } // Insert WP comment $comment_text = "<span>" . __('Buyer Submitted Counter Offer', $this->plugin_slug) . "</span>"; if ($comments != '') { // Insert WP comment $comment_text .= '<br />' . $comments; } $data = array('comment_post_ID' => '', 'comment_author' => 'admin', 'comment_author_email' => '', 'comment_author_url' => '', 'comment_content' => $comment_text, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => '', 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => '', 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'comment_approved' => 'post-trashed'); $new_comment_id = wp_insert_comment($data); // insert comment meta if ($new_comment_id) { add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $parent_post_id, true); } } else { // Insert new Post $parent_post_id = wp_insert_post($newPostData); if ($parent_post_id) { // Insert new Post Meta Values foreach ($formData as $k => $v) { $newPostMetaData = array(); $newPostMetaData['post_id'] = $parent_post_id; $newPostMetaData['meta_key'] = $k; $newPostMetaData['meta_value'] = $v; add_post_meta($newPostMetaData['post_id'], $newPostMetaData['meta_key'], $newPostMetaData['meta_value']); } // Insert WP comment $comment_text = "<span>" . __('Created New Offer', $this->plugin_slug) . "</span>"; if ($comments != '') { // Insert WP comment $comment_text .= '<br />' . $comments; } $data = array('comment_post_ID' => '', 'comment_author' => 'admin', 'comment_author_email' => '', 'comment_author_url' => '', 'comment_content' => $comment_text, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 1, 'comment_author_IP' => '127.0.0.1', 'comment_agent' => '', 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'comment_approved' => 'post-trashed'); $new_comment_id = wp_insert_comment($data); // insert comment meta if ($new_comment_id) { add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $parent_post_id, true); } } else { // return error msg echo json_encode(array("statusmsg" => 'failed', "statusmsgDetail" => 'database error')); exit; } } /** * Email Out - admin email notification of new or countered offer * @since 0.1.0 */ $offer_id = $parent_post_id; $offer_name = get_post_meta($parent_post_id, 'offer_name', true); $offer_phone = get_post_meta($parent_post_id, 'offer_phone', true); $offer_company_name = get_post_meta($parent_post_id, 'offer_company_name', true); $offer_email = get_post_meta($parent_post_id, 'offer_email', true); $product_id = get_post_meta($parent_post_id, 'offer_product_id', true); $variant_id = get_post_meta($parent_post_id, 'offer_variation_id', true); $_pf = new WC_Product_Factory(); $product = $variant_id ? $_pf->get_product($variant_id) : $_pf->get_product($product_id); $product_qty = $formData['offer_quantity']; $product_price_per = $formData['offer_price_per']; $product_total = $formData['offer_amount']; $offer_args = array('offer_email' => $offer_email, 'offer_name' => $offer_name, 'offer_phone' => $offer_phone, 'offer_company_name' => $offer_company_name, 'offer_id' => $offer_id, 'product_id' => $product_id, 'product_url' => get_permalink($product_id), 'variant_id' => $variant_id, 'product' => $product, 'product_qty' => $product_qty, 'product_price_per' => $product_price_per, 'product_total' => $product_total, 'offer_notes' => $comments); if ($variant_id) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product->variation_id; } $attributes = $product->get_variation_attributes(); $extra_data = ' – ' . implode(', ', $attributes); $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'woocommerce'), $identifier, $product->get_title(), $extra_data); } else { if (!empty($product)) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product_id; } $offer_args['product_title_formatted'] = sprintf(__('%s – %s', 'woocommerce'), $identifier, $product->get_title()); } if ($is_counter_offer) { $offer_args['is_counter_offer'] = true; /** * send admin 'New counter offer' email template */ // the email we want to send $email_class = 'WC_New_Counter_Offer_Email'; } else { $offer_args['is_counter_offer'] = false; /** * send admin 'New offer' email template */ // the email we want to send $email_class = 'WC_New_Offer_Email'; } // load the WooCommerce Emails $wc_emails = new WC_Emails(); $emails = $wc_emails->get_emails(); // select the email we want & trigger it to send $new_email = $emails[$email_class]; // set plugin slug in email class $new_email->plugin_slug = $this->plugin_slug; if ($is_counter_offer) { // define email template/path (html) $new_email->template_html = 'woocommerce-new-counter-offer.php'; $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/'; // define email template/path (plain) $new_email->template_plain = 'woocommerce-new-counter-offer.php'; $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/'; } else { // define email template/path (html) $new_email->template_html = 'woocommerce-new-offer.php'; $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/'; // define email template/path (plain) $new_email->template_plain = 'woocommerce-new-offer.php'; $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/'; } $new_email->trigger($offer_args); /** * Send buyer 'offer received' email notification */ // the email we want to send $email_class = 'WC_Offer_Received_Email'; // set recipient $recipient = $offer_email; $offer_args['recipient'] = $offer_email; // select the email we want & trigger it to send $new_email = $emails[$email_class]; $new_email->recipient = $recipient; // set plugin slug in email class $new_email->plugin_slug = $this->plugin_slug; // define email template/path (html) $new_email->template_html = 'woocommerce-offer-received.php'; $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/'; // define email template/path (plain) $new_email->template_plain = 'woocommerce-offer-received.php'; $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/'; $new_email->trigger($offer_args); // Success echo json_encode(array("statusmsg" => 'success')); exit; } } }
/** * Send proforma invoice when order is created with status pending * * @access public * @param int $order_id * @param array $posted * @return void */ public function new_order($order_id, $posted) { if ($this->opt['woo_pdf_send_customer_invoice'] && class_exists('WC_Emails')) { $order = new WC_Order($order_id); $wc_emails = WC_Emails::instance(); if (is_object($order) && is_object($wc_emails) && method_exists($wc_emails, 'customer_invoice')) { $wc_emails->customer_invoice($order); } } }
/** * Email Class. * @return WC_Emails */ public function mailer() { return WC_Emails::instance(); }
/** * * @global type $wpdb * @param type $offer_id * @param type $emails * @since 1.2.0 */ public function ofw_auto_decline_offer($offer_id = null, $emails = null) { global $wpdb; if (isset($_POST["targetID"]) && !empty($_POST["targetID"])) { $post_id = $_POST["targetID"]; } else { $post_id = $offer_id; } if (isset($post_id) && !empty($post_id)) { $post_data = get_post($post_id); $is_offer_buyer_countered_status = $post_data->post_status == 'buyercountered-offer' ? true : false; $table = $wpdb->prefix . "posts"; $data_array = array('post_status' => 'declined-offer', 'post_modified' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'post_modified_gmt' => date("Y-m-d H:i:s", current_time('timestamp', 1))); $where = array('ID' => $post_id); $wpdb->update($table, $data_array, $where); $post_status_text = __('Declined', $this->plugin_slug); $offer_notes = isset($_POST['angelleye_woocommerce_offer_status_notes']) && $_POST['angelleye_woocommerce_offer_status_notes'] != '' ? $_POST['angelleye_woocommerce_offer_status_notes'] : ''; $recipient = get_post_meta($post_id, 'offer_email', true); $offer_id = $post_id; $offer_uid = get_post_meta($post_id, 'offer_uid', true); $offer_name = get_post_meta($post_id, 'offer_name', true); $offer_email = $recipient; $product_id = get_post_meta($post_id, 'offer_product_id', true); $variant_id = get_post_meta($post_id, 'offer_variation_id', true); $_pf = new WC_Product_Factory(); $product = $variant_id ? $_pf->get_product($variant_id) : $_pf->get_product($product_id); $product_qty = $is_offer_buyer_countered_status ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true); $product_price_per = $is_offer_buyer_countered_status ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true); $product_total = $product_qty * $product_price_per; if ($is_offer_buyer_countered_status) { update_post_meta($post_id, 'offer_quantity', $product_qty); update_post_meta($post_id, 'offer_price_per', $product_price_per); update_post_meta($post_id, 'offer_amount', $product_total); } $offer_args = array('recipient' => $recipient, 'offer_email' => $offer_email, 'offer_name' => $offer_name, 'offer_id' => $offer_id, 'offer_uid' => $offer_uid, 'product_id' => $product_id, 'product_url' => $product->get_permalink(), 'variant_id' => $variant_id, 'product' => $product, 'product_qty' => $product_qty, 'product_price_per' => $product_price_per, 'product_total' => $product_total, 'offer_notes' => $offer_notes); if ($variant_id) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product->variation_id; } $attributes = $product->get_variation_attributes(); $extra_data = ' – ' . implode(', ', $attributes); $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'woocommerce'), $identifier, $product->get_title(), $extra_data); } else { $offer_args['product_title_formatted'] = $product->get_formatted_name(); } $email_class = 'WC_Declined_Offer_Email'; if (empty($emails)) { $wc_emails = new WC_Emails(); $emails = $wc_emails->get_emails(); } $new_email = $emails[$email_class]; $new_email->recipient = $recipient; $new_email->plugin_slug = $this->plugin_slug; $new_email->template_html = 'woocommerce-offer-declined.php'; $new_email->template_html_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/'; $new_email->template_plain = 'woocommerce-offer-declined.php'; $new_email->template_plain_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/plain/'; $new_email->trigger($offer_args); $comment_text = "<span>Updated - Status: </span>"; $comment_text .= $post_status_text; if (isset($offer_notes) && $offer_notes != '') { $comment_text .= '</br>' . nl2br($offer_notes); } $data = array('comment_post_ID' => '', 'comment_author' => 'admin', 'comment_author_email' => '', 'comment_author_url' => '', 'comment_content' => $comment_text, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => get_current_user_id(), 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => '', 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)), 'comment_approved' => 'post-trashed'); $new_comment_id = wp_insert_comment($data); if ($new_comment_id) { add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true); } } }