instance() public static method

Ensures only one instance of WC_Emails is loaded or can be loaded.
Since: 2.1
public static instance ( ) : WC_Emails
return WC_Emails Main 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);
 }
 /**
  * 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()));
         }
     }
 }
 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);
         }
     }
 }
Beispiel #6
0
 /**
  * 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;
     }
 }
Beispiel #8
0
 /**
  * Email Class.
  * @return WC_Emails
  */
 public function mailer()
 {
     return WC_Emails::instance();
 }
Beispiel #9
0
 /**
  * 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);
 }
 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);
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
         }
     }
 }
Beispiel #14
0
	/**
	 * 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 );
		}
	}
Beispiel #15
0
 /**
  * Send an email
  *
  * @param Email $email
  * @param string $recipient
  *
  * @return bool
  */
 public function send(Email $email, $recipient)
 {
     $wc_emails = \WC_Emails::instance();
     return $wc_emails->send($recipient, $email->get_subject(), $email->get_content());
 }