/**
  * WooCommerce compatible function to send email
  */
 public static function mail($to, $subject, $message)
 {
     if (self::is_wc_gte_21()) {
         wc_mail($to, $subject, $message);
     } else {
         woocommerce_mail($to, $subject, $message);
     }
 }
 /**
  * Function to send e-mail containing coupon code to customer
  *
  * @param array $coupon_title associative array containing receiver's details
  * @param string $discount_type
  * @param int $order_id
  * @param array $gift_certificate_receiver_name array of receiver's name
  * @param string $message_from_sender
  * @param string $gift_certificate_sender_name
  * @param string $gift_certificate_sender_email
  * @param boolean $is_gift whether it is a gift certificate or store credit
  */
 public function sa_email_coupon($coupon_title, $discount_type, $order_id = '', $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '', $is_gift = '')
 {
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $url = get_option('permalink_structure') ? get_permalink(woocommerce_get_page_id('shop')) : get_post_type_archive_link('product');
     if ($discount_type == 'smart_coupon' && $is_gift == 'yes') {
         $gift_certificate_sender_name = trim($gift_certificate_sender_name);
         $sender = !empty($gift_certificate_sender_name) ? $gift_certificate_sender_name : '';
         $sender .= !empty($gift_certificate_sender_name) ? ' (' : '';
         $sender .= !empty($gift_certificate_sender_email) ? $gift_certificate_sender_email : '';
         $sender .= !empty($gift_certificate_sender_name) ? ')' : '';
         $from = ' ' . __('from', self::$text_domain) . ' ';
         $smart_coupon_type = __('Gift Card', self::$text_domain);
     } else {
         $from = '';
         $smart_coupon_type = __('Store Credit', self::$text_domain);
     }
     $subject_string = sprintf(__("Congratulations! You've received a %s ", self::$text_domain), $discount_type == 'smart_coupon' && !empty($smart_coupon_type) ? $smart_coupon_type : 'coupon');
     $subject_string = get_option('smart_coupon_email_subject') && get_option('smart_coupon_email_subject') != '' ? __(get_option('smart_coupon_email_subject'), self::$text_domain) : $subject_string;
     $subject_string .= !empty($gift_certificate_sender_name) ? $from . $gift_certificate_sender_name : '';
     $subject = apply_filters('woocommerce_email_subject_gift_certificate', sprintf('%s: %s', $blogname, $subject_string));
     foreach ($coupon_title as $email => $coupon) {
         $amount = $coupon['amount'];
         $coupon_code = $coupon['code'];
         switch ($discount_type) {
             case 'smart_coupon':
                 $email_heading = sprintf(__('You have received %s worth %s ', self::$text_domain), $smart_coupon_type, $this->wc_price($amount));
                 break;
             case 'fixed_cart':
                 $email_heading = sprintf(__('You have received a coupon worth %s (on entire purchase) ', self::$text_domain), $this->wc_price($amount));
                 break;
             case 'fixed_product':
                 $email_heading = sprintf(__('You have received a coupon worth %s (for a product) ', self::$text_domain), $this->wc_price($amount));
                 break;
             case 'percent_product':
                 $email_heading = sprintf(__('You have received a coupon worth %s%% (for a product) ', self::$text_domain), $amount);
                 break;
             case 'percent':
                 $email_heading = sprintf(__('You have received a coupon worth %s%% (on entire purchase) ', self::$text_domain), $amount);
                 break;
         }
         if (empty($email)) {
             $email = $gift_certificate_sender_email;
         }
         if (!empty($order_id)) {
             $coupon_receiver_details = get_post_meta($order_id, 'sc_coupon_receiver_details', true);
             if (!is_array($coupon_receiver_details) || empty($coupon_receiver_details)) {
                 $coupon_receiver_details = array();
             }
             $coupon_receiver_details[] = array('code' => $coupon_code, 'amount' => $amount, 'email' => $email, 'message' => $message_from_sender);
             update_post_meta($order_id, 'sc_coupon_receiver_details', $coupon_receiver_details);
         }
         ob_start();
         include apply_filters('woocommerce_gift_certificates_email_template', 'templates/email.php');
         $message = ob_get_clean();
         woocommerce_mail($email, $subject, $message);
     }
 }
Esempio n. 3
0
function send_user_approve_email($user_id)
{
    global $woocommerce;
    //Instantiate mailer
    $mailer = $woocommerce->mailer();
    if (!$user_id) {
        return;
    }
    $user = new WP_User($user_id);
    $user_login = stripslashes($user->user_login);
    $user_email = stripslashes($user->user_email);
    $user_pass = "******";
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $blogname_replaced = str_replace('Degreaser', 'Solvent', $blogname);
    $subject = apply_filters('woocommerce_email_subject_customer_new_account', sprintf(__('Your account on %s has been approved!', 'woocommerce'), $blogname_replaced), $user);
    $email_heading = "User {$user_login} has been approved";
    // Buffer
    ob_start();
    // Get mail template
    woocommerce_get_template('emails/customer-account-approved.php', array('user_login' => $user_login, 'user_pass' => $user_pass, 'blogname' => $blogname, 'email_heading' => $email_heading));
    // Get contents
    $message = ob_get_clean();
    // Send the mail
    woocommerce_mail($user_email, $subject, $message, $headers = "Content-Type: text/htmlrn", $attachments = "");
}
Esempio n. 4
0
function woo_ce_cron_export( $gui = '', $type = '', $is_scheduled = false ) {

	global $export;

	$export = new stdClass;
	$export->cron = ( $is_scheduled ? 0 : 1 );
	$export->scheduled_export = ( $is_scheduled ? 1 : 0 );
	$export->start_time = time();
	$export->idle_memory_start = woo_ce_current_memory_usage();
	$export->error = '';

	$bits = '';
	$type = ( isset( $_GET['type'] ) ? $_GET['type'] : $type );
	if( empty( $type ) ) {
		if( $gui == 'gui' ) {
			$output = sprintf( '<p>%s</p>', __( 'No export type was provided.', 'woo_ce' ) );
		} else {
			error_log( sprintf( '[store-exporter-deluxe] -: Error: %s', __( 'No export type was provided', 'woo_ce' ) ) );
			return false;
		}
	} else {
		$types = array_keys( woo_ce_return_export_types() );
		$export->type = $type;
		// Check that export is in the list of available exports
		if( !in_array( $export->type, $types ) ) {
			if( $gui == 'gui' ) {
				$output = '<p>' . __( 'An invalid export type was provided.', 'woo_ce' ) . '</p>';
			} else {
				error_log( sprintf( '[store-exporter-deluxe] -: Error: %s', __( 'An invalid export type was provided', 'woo_ce' ) ) );
				return false;
			}
		} else {
			$export->export_format = ( isset( $_GET['format'] ) ? sanitize_text_field( $_GET['format'] ) : woo_ce_get_option( 'export_format', 'csv' ) );

			// Override the export format if outputting to screen in friendly design
			if( $gui == 'gui' && in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) )
				$export->export_format = 'csv';

			// Override the export format if this is a scheduled export
			if( $export->scheduled_export )
				$export->export_format = woo_ce_get_option( 'auto_format', 'csv' );

			// Override the export format if the single order Transient is set
			$single_export_format = get_transient( WOO_CD_PREFIX . '_single_export_format' );
			if( $single_export_format !== false )
				$export->export_format = $single_export_format;
			unset( $single_export_format );

			$export->delimiter = ( isset( $_GET['delimiter'] ) ? sanitize_text_field( $_GET['delimiter'] ) : woo_ce_get_option( 'delimiter', ',' ) );
			if( $export->delimiter == '' || $export->delimiter == false ) {
				error_log( '[store-exporter-deluxe] Warning: Delimiter export option was corrupted, defaulted to ,' );
				$export->delimiter = ',';
				woo_ce_update_option( 'delimiter', ',' );
			} else if( $export->delimiter == 'TAB' ) {
				$export->delimiter = "\t";
			}
			$export->category_separator = ( isset( $_GET['category_separator'] ) ? sanitize_text_field( $_GET['category_separator'] ) : woo_ce_get_option( 'category_separator', '|' ) );
			// Override for line break (LF) support in Category Separator
			if( $export->category_separator == 'LF' )
				$export->category_separator = "\n";
			$export->bom = ( isset( $_GET['bom'] ) ? absint( $_GET['bom'] ) : woo_ce_get_option( 'bom', 1 ) );
			$export->encoding = ( isset( $_GET['encoding'] ) ? sanitize_text_field( $_GET['encoding'] ) : woo_ce_get_option( 'encoding', 'UTF-8' ) );
			$export->timeout = woo_ce_get_option( 'timeout', 600 );
			$export->escape_formatting = ( isset( $_GET['escape_formatting'] ) ? sanitize_text_field( $_GET['escape_formatting'] ) : woo_ce_get_option( 'escape_formatting', 'all' ) );
			$export->header_formatting = ( isset( $_GET['header_formatting'] ) ? absint( $_GET['header_formatting'] ) : woo_ce_get_option( 'header_formatting', 1 ) );
			$export->date_format = woo_ce_get_option( 'date_format', 'd/m/Y' );
			$export->order_items = ( isset( $_GET['order_items'] ) ? sanitize_text_field( $_GET['order_items'] ) : woo_ce_get_option( 'order_items_formatting', 'unique' ) );
			$export->order_items_types = ( isset( $_GET['order_items_types'] ) ? sanitize_text_field( $_GET['order_items_types'] ) : woo_ce_get_option( 'order_items_types', false ) );
			$export->upsell_formatting = woo_ce_get_option( 'upsell_formatting', 1 );
			$export->crosssell_formatting = woo_ce_get_option( 'crosssell_formatting', 1 );
			$export->gallery_formatting = woo_ce_get_option( 'gallery_formatting', 0 );
			$export->gallery_unique = woo_ce_get_option( 'gallery_unique', 0 );
			$export->max_product_gallery = woo_ce_get_option( 'max_product_gallery', 3 );
			$export->filename = woo_ce_generate_filename( $export->type );
			switch( $export->export_format ) {

				case 'csv':
					$php_excel_format = 'SED_CSV';
					$file_extension = 'csv';
					$post_mime_type = 'text/csv';
					break;

				case 'xls':
					$php_excel_format = 'Excel5';
					$file_extension = 'xls';
					$post_mime_type = 'application/vnd.ms-excel';
					break;

				case 'xlsx':
					$php_excel_format = 'Excel2007';
					$file_extension = 'xlsx';
					$post_mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
					break;

				case 'xml':
					$file_extension = 'xml';
					$post_mime_type = 'application/xml';
					break;

				case 'rss':
					$file_extension = 'xml';
					$post_mime_type = 'application/rss+xml';
					break;

				default:
					error_log( sprintf( '[store-exporter-deluxe] -: Warning: %s', __( 'An invalid export format was provided', 'woo_ce' ) ) );
					return;
					break;

			}
			$export->filename = $export->filename . '.' . $file_extension;
			$export->limit_volume = ( isset( $_GET['limit'] ) ? absint( $_GET['limit'] ) : -1 );
			$export->offset = ( isset( $_GET['offset'] ) ? absint( $_GET['offset'] ) : 0 );
			// Select all export fields for CRON export
			$export->fields = woo_ce_cron_export_fields( $export->type, $export->scheduled_export );
			// Grab to value if response is e-mail or remote POST
			if( in_array( $gui, array( 'email', 'post' ) ) ) {
				if( $gui == 'email' )
					$export->to = ( isset( $_GET['to'] ) ? sanitize_email( $_GET['to'] ) : woo_ce_get_option( 'email_to', '' ) );
				else if( $gui == 'post' )
					$export->to = ( isset( $_GET['to'] ) ? esc_url_raw( $_GET['to'] ) : woo_ce_get_option( 'post_to', '' ) );
			}
			$export = woo_ce_check_cron_export_arguments( $export );

			$export->args = array(
				'limit_volume' => $export->limit_volume,
				'offset' => $export->offset,
				'encoding' => $export->encoding,
				'date_format' => $export->date_format,
				'order_items' => $export->order_items,
				'order_items_types' => $export->order_items_types
			);

			$orderby = ( isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : null );
			$order = ( isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : null );
			switch( $export->type ) {

				case 'product':
					$export->args['product_orderby'] = $orderby;
					$export->args['product_order'] = $order;
					if( $export->scheduled_export ) {
						$product_filter_type = woo_ce_get_option( 'auto_product_type', false );
						$product_filter_status = woo_ce_get_option( 'auto_product_status', false );
						$product_filter_stock = woo_ce_get_option( 'auto_product_stock', false );
						$product_filter_category = woo_ce_get_option( 'auto_product_category', false );
						$product_filter_tag = woo_ce_get_option( 'auto_product_tag', false );
						$export->args['product_type'] = ( !empty( $product_filter_type ) ? $product_filter_type : false );
						$export->args['product_status'] = ( !empty( $product_filter_status ) ? $product_filter_status : false );
						$export->args['product_stock'] = ( !empty( $product_filter_stock ) ? $product_filter_stock : false );
						$export->args['product_categories'] = ( !empty( $product_filter_category ) ? $product_filter_category : false );
						$export->args['product_tags'] = ( !empty( $product_filter_tag ) ? $product_filter_tag : false );
					} else {
						$export->args['product_status'] = ( isset( $_GET['product_status'] ) ? sanitize_text_field( $_GET['product_status'] ) : null );
						$export->args['product_stock'] = ( isset( $_GET['stock_status'] ) ? sanitize_text_field( $_GET['stock_status'] ) : null );
					}
					break;

				case 'category':
					$export->args['category_orderby'] = $orderby;
					$export->args['category_order'] = $order;
					break;

				case 'tag':
					$export->args['tag_orderby'] = $orderby;
					$export->args['tag_order'] = $order;
					break;

				case 'order':
					$export->args['order_orderby'] = $orderby;
					$export->args['order_order'] = $order;
					$export->args['order_ids'] = ( isset( $_GET['order_ids'] ) ? sanitize_text_field( $_GET['order_ids'] ) : null );

					// Override Filter Orders by Order ID if a single order transient is set
					$single_export_order_ids = get_transient( WOO_CD_PREFIX . '_single_export_order_ids' );
					if( $single_export_order_ids !== false )
						$export->args['order_ids'] = sanitize_text_field( $single_export_order_ids );
					unset( $single_export_order_ids );

					if( $export->scheduled_export ) {

						// Scheduled export engine

						// Order Status
						$order_filter_status = woo_ce_get_option( 'auto_order_status', '' );
						$export->args['order_status'] = ( !empty( $order_filter_status ) ? (array)$order_filter_status : array() );
						// Order Date
						$order_dates_filter = woo_ce_get_option( 'auto_order_date', false );
						if( $order_dates_filter ) {
							$export->args['order_dates_filter'] = $order_dates_filter;
							switch( $order_dates_filter ) {

								case 'manual':
									$order_filter_dates_from = woo_ce_get_option( 'auto_order_dates_from', false );
									$order_filter_dates_to = woo_ce_get_option( 'auto_order_dates_to', false );
									$export->args['order_dates_from'] = ( !empty( $order_filter_dates_from ) ? sanitize_text_field( $order_filter_dates_from ) : false );
									$export->args['order_dates_to'] = ( !empty( $order_filter_dates_to ) ? sanitize_text_field( $order_filter_dates_to ) : false );
									break;

								case 'variable':
									$order_filter_date_variable = woo_ce_get_option( 'auto_order_date_variable', false );
									$order_filter_date_variable_length = woo_ce_get_option( 'auto_order_date_variable_length', false );
									$export->args['order_dates_filter_variable'] = ( !empty( $order_filter_date_variable ) ? absint( $order_filter_date_variable ) : false );
									$export->args['order_dates_filter_variable_length'] = ( !empty( $order_filter_date_variable_length ) ? sanitize_text_field( $order_filter_date_variable_length ) : false );
									break;

							}
						}
						// Product
						$order_filter_product = woo_ce_get_option( 'auto_order_product', '' );
						$export->args['order_product'] = ( !empty( $order_filter_product ) ? (array)$order_filter_product : array() );
						// Billing Country
						$order_filter_billing_country = woo_ce_get_option( 'auto_order_billing_country', false );
						$export->args['order_billing_country'] = ( !empty( $order_filter_billing_country ) ? array_map( 'sanitize_text_field', $order_filter_billing_country ) : false );
						// Shipping Country
						$order_filter_shipping_country = woo_ce_get_option( 'auto_order_shipping_country', false );
						$export->args['order_shipping_country'] = ( !empty( $order_filter_shipping_country ) ? array_map( 'sanitize_text_field', $order_filter_shipping_country ) : false );
						// Payment Gateway
						$order_filter_payment = woo_ce_get_option( 'auto_order_payment', array() );
						$export->args['order_payment'] = ( !empty( $order_filter_payment ) ? array_map( 'sanitize_text_field', $order_filter_payment ) : false );
						// Shipping Method
						$order_filter_shipping = woo_ce_get_option( 'auto_order_shipping', array() );
						$export->args['order_shipping'] = ( !empty( $order_filter_shipping ) ? array_map( 'sanitize_text_field', $order_filter_shipping ) : false );
					} else {

						// CRON export engine

						// Order Status
						if( isset( $_GET['order_status'] ) ) {
							$order_filter_status = sanitize_text_field( $_GET['order_status'] );
							$order_filter_status = explode( ',', $order_filter_status );
							$export->args['order_status'] = $order_filter_status;
						}
						// Product
						if( isset( $_GET['order_product'] ) ) {
							$order_filter_product = sanitize_text_field( $_GET['order_product'] );
							$order_filter_product = explode( ',', $order_filter_product );
							$export->args['order_product'] = $order_filter_product;
						}
						// Order Date
						if( isset( $_GET['order_date_from'] ) && isset( $_GET['order_date_to'] ) ) {
							$order_filter_dates_from = $_GET['order_date_from'];
							$order_filter_dates_to = $_GET['order_date_to'];
							$export->args['order_dates_filter'] = 'manual';
							$export->args['order_dates_from'] = ( !empty( $order_filter_dates_from ) ? sanitize_text_field( $order_filter_dates_from ) : false );
							$export->args['order_dates_to'] = ( !empty( $order_filter_dates_to ) ? sanitize_text_field( $order_filter_dates_to ) : false );
						}
						// Billing Country
						if( isset( $_GET['billing_country'] ) ) {
							$order_filter_billing_country = sanitize_text_field( $_GET['billing_country'] );
							$order_filter_billing_country = explode( ',', $order_filter_billing_country );
							$export->args['order_billing_country'] = ( !empty( $order_filter_billing_country ) ? $order_filter_billing_country : false );
						}
						// Shipping Country
						if( isset( $_GET['shipping_country'] ) ) {
							$order_filter_shipping_country = sanitize_text_field( $_GET['shipping_country'] );
							$order_filter_shipping_country = explode( ',', $order_filter_shipping_country );
							$export->args['order_shipping_country'] = ( !empty( $order_filter_shipping_country ) ? $order_filter_shipping_country : false );
						}
						// Payment Gateway
						if( isset( $_GET['payment_gateway'] ) ) {
							$order_filter_payment = sanitize_text_field( $_GET['order_payment'] );
							$order_filter_payment = explode( ',', $order_filter_payment );
							$export->args['order_payment'] = ( !empty( $order_filter_payment ) ? $order_filter_payment : false );
						}
						// Shipping Method
						if( isset( $_GET['shipping_method'] ) ) {
							$order_filter_shipping = sanitize_text_field( $_GET['shipping_method'] );
							$order_filter_shipping = explode( ',', $order_filter_shipping );
							$export->args['order_shipping'] = ( !empty( $order_filter_shipping ) ? $order_filter_shipping : false );
						}
					}
					break;

				case 'subscription':
					$export->args['subscription_orderby'] = $orderby;
					$export->args['subscription_order'] = $order;
					break;

				case 'product_vendor':
					$export->args['product_vendor_orderby'] = $orderby;
					$export->args['product_vendor_order'] = $order;
					break;

				case 'commission':
					// Commission Date
					$commission_dates_filter = woo_ce_get_option( 'auto_commission_date', false );
					if( $commission_dates_filter ) {
						$export->args['commission_dates_filter'] = $commission_dates_filter;
						switch( $commission_dates_filter ) {

							case 'manual':
								$commission_filter_dates_from = woo_ce_get_option( 'auto_commission_dates_from', false );
								$commission_filter_dates_to = woo_ce_get_option( 'auto_commission_date_to', false );
								$export->args['commission_dates_from'] = ( !empty( $commission_filter_dates_from ) ? sanitize_text_field( $commission_filter_dates_from ) : false );
								$export->args['commission_dates_to'] = ( !empty( $commission_filter_dates_to ) ? sanitize_text_field( $commission_filter_dates_to ) : false );
								break;

							case 'variable':
								$commission_filter_date_variable = woo_ce_get_option( 'auto_commission_date_variable', false );
								$commission_filter_date_variable_length = woo_ce_get_option( 'auto_commission_date_variable_length', false );
								$export->args['commission_dates_filter_variable'] = ( !empty( $commission_filter_date_variable ) ? absint( $commission_filter_date_variable ) : false );
								$export->args['commission_dates_filter_variable_length'] = ( !empty( $commission_filter_date_variable_length ) ? sanitize_text_field( $commission_filter_date_variable_length ) : false );
								break;

						}
					}
					break;

				case 'shipping_class':
					$export->args['shipping_class_orderby'] = $orderby;
					$export->args['shipping_class_order'] = $order;
					break;

			}
			$export->filename = woo_ce_generate_filename( $export->type ) . '.' . $file_extension;
			// Let's spin up PHPExcel for supported Export Types and Export Formats
			if( in_array( $export->export_format, array( 'csv', 'xls', 'xlsx' ) ) ) {
				// Check if we are using PHPExcel or not for supported Export Types
				$dataset = woo_ce_export_dataset( $export->type );
				if( !empty( $dataset ) ) {
					// Check that PHPExcel is where we think it is
					if( file_exists( WOO_CD_PATH . 'classes/PHPExcel.php' ) ) {
						// Check if PHPExcel has already been loaded
						if( !class_exists( 'PHPExcel' ) ) {
							include_once( WOO_CD_PATH . 'classes/PHPExcel.php' );
						} else {
							error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, __( 'The PHPExcel library was already loaded by another WordPress Plugin, if there\'s issues with your export file you know where to look.', 'woo_ce' ) ) );
						}
						$excel = new PHPExcel();
						$excel->setActiveSheetIndex( 0 );
						$excel->getActiveSheet()->setTitle( ucfirst( $export->type ) );
						$row = 1;
						// Skip headers if Heading Formatting is turned off
						if( $export->header_formatting ) {
							$col = 0;
							foreach( $export->columns as $column ) {
								$excel->getActiveSheet()->setCellValueByColumnAndRow( $col, $row, $column );
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( true );
								$excel->getActiveSheet()->getColumnDimensionByColumn( $col )->setAutoSize( true );
								$col++;
							}
							$row = 2;
						}
						foreach( $dataset as $data ) {
							$col = 0;
							foreach( array_keys( $export->fields ) as $field ) {
								$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->getStyle()->getFont()->setBold( false );
								if( $export->encoding == 'UTF-8' ) {
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? wp_specialchars_decode( $data->$field ) : '' ) );
									}
								} else {
									// PHPExcel only deals with UTF-8 regardless of encoding type
									if( woo_ce_detect_value_string( ( isset( $data->$field ) ? $data->$field : null ) ) ) {
										// Treat this cell as a string
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValueExplicit( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ), PHPExcel_Cell_DataType::TYPE_STRING );
									} else {
										$excel->getActiveSheet()->getCellByColumnAndRow( $col, $row )->setValue( ( isset( $data->$field ) ? utf8_encode( wp_specialchars_decode( $data->$field ) ) : '' ) );
									}
								}
								$col++;
							}
							$row++;
						}
						switch( $export->export_format ) {

							case 'csv':
								// We need to load this after the PHPExcel Class has been created
								woo_cd_load_phpexcel_sed_csv_writer();
								break;

						}
						$objWriter = PHPExcel_IOFactory::createWriter( $excel, $php_excel_format );
						switch( $export->export_format ) {

							case 'csv':
								$objWriter->setUseBOM( true );
								// Check if we're using a non-standard delimiter
								if( $export->delimiter != ',' )
									$objWriter->setDelimiter( $export->delimiter );
								break;

							case 'xlsx':
								$objWriter->setPreCalculateFormulas( false );
								break;

						}
						if( in_array( $gui, array( 'raw' ) ) ) {
							$objWriter->save( 'php://output' );
						} else {
							// Save to file and insert to WordPress Media
							$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
							// Check if we were given a temporary filename
							if( $temp_filename == false ) {
								$message = sprintf( __( 'We could not create a temporary export file in %s, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $message ) );
							} else {
								$objWriter->save( $temp_filename );
								$bits = file_get_contents( $temp_filename );
							}
							unlink( $temp_filename );
						}

						// Clean up PHPExcel
						$excel->disconnectWorksheets();
						unset( $objWriter, $excel );

					} else {
						error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'We couldn\'t load the PHPExcel library, this file should be present.' ) ) );
					}
				}
			// Run the default engine for the XML and RSS export formats
			} else if( in_array( $export->export_format, array( 'xml', 'rss' ) ) ) {
				// Check if SimpleXMLElement is present
				if( class_exists( 'SED_SimpleXMLElement' ) ) {
					if( $export->export_format == 'xml' ) {
						$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_xml_first_line', '<?xml version="1.0" encoding="%s"?><%s/>' ), esc_attr( $export->encoding ), esc_attr( apply_filters( 'woo_ce_export_xml_store_node', 'store' ) ) ) );
						if( woo_ce_get_option( 'xml_attribute_url', 1 ) )
							$xml->addAttribute( 'url', get_site_url() );
						if( woo_ce_get_option( 'xml_attribute_date', 1 ) )
							$xml->addAttribute( 'date', date( 'Y-m-d' ) );
						if( woo_ce_get_option( 'xml_attribute_time', 0 ) )
							$xml->addAttribute( 'time', date( 'H:i:s' ) );
						if( woo_ce_get_option( 'xml_attribute_title', 1 ) )
							$xml->addAttribute( 'name', htmlspecialchars( get_bloginfo( 'name' ) ) );
						if( woo_ce_get_option( 'xml_attribute_export', 1 ) )
							$xml->addAttribute( 'export', htmlspecialchars( $export->type ) );
						if( woo_ce_get_option( 'xml_attribute_orderby', 1 ) )
							$xml->addAttribute( 'orderby', $orderby );
						if( woo_ce_get_option( 'xml_attribute_order', 1 ) )
							$xml->addAttribute( 'order', $order );
						if( woo_ce_get_option( 'xml_attribute_limit', 1 ) )
							$xml->addAttribute( 'limit', $export->limit_volume );
						if( woo_ce_get_option( 'xml_attribute_offset', 1 ) )
							$xml->addAttribute( 'offset', $export->offset );
						$xml = woo_ce_export_dataset( $export->type, $xml );
					} else if( $export->export_format == 'rss' ) {
						$xml = new SED_SimpleXMLElement( sprintf( apply_filters( 'woo_ce_export_rss_first_line', '<?xml version="1.0" encoding="%s"?><rss version="2.0"%s/>' ), esc_attr( $export->encoding ), ' xmlns:g="http://base.google.com/ns/1.0"' ) );
						$child = $xml->addChild( apply_filters( 'woo_ce_export_rss_channel_node', 'channel' ) );
						$child->addChild( 'title', woo_ce_get_option( 'rss_title', '' ) );
						$child->addChild( 'link', woo_ce_get_option( 'rss_link', '' ) );
						$child->addChild( 'description', woo_ce_get_option( 'rss_description', '' ) );
						$bits = woo_ce_export_dataset( $export->type, $child );
					}
					$bits = woo_ce_format_xml( $xml );
				} else {
					$bits = false;
					error_log( '[store-exporter-deluxe] Error: The SimpleXMLElement class does not exist for XML file generation' );
				}
			}
			if( !empty( $bits ) ) {
				$output = '<p>' . __( 'Export completed successfully.', 'woo_ce' ) . '</p>';
				if( $gui == 'gui' )
					$output .= '<textarea readonly="readonly">' . esc_textarea( str_replace( '<br />', "\n", $bits ) ) . '</textarea>';
			} else {
				if( $gui == 'gui' ) {
					$output = sprintf( '<p>%s</p>', __( 'No export entries were found.', 'woo_ce' ) );
				} else {
					error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, __( 'No export entries were found', 'woo_ce' ) ) );
					return false;
				}
			}
		}
	}

	// Return raw export to browser without file headers
	if( $gui == 'raw' && !empty( $bits ) ) {
		return $bits;
	// Return export as file download to browser
	} else if( $gui == 'download' && !empty( $bits ) ) {
		woo_ce_generate_file_headers( $post_mime_type );
		if( defined( 'DOING_AJAX' ) || get_transient( WOO_CD_PREFIX . '_single_export_format' ) !== false )
			echo $bits;
		else
			return $bits;
	// HTTP Post export contents to remote URL
	} else if( $gui == 'post' && !empty( $bits ) ) {
		$args = apply_filters( 'woo_ce_cron_export_post_args', array(
			'method'      => 'POST',
			'timeout'     => 60,
			'redirection' => 0,
			'httpversion' => '1.0',
			'sslverify'   => false,
			'blocking'    => true,
			'headers'     => array(
				'accept'       => $post_mime_type,
				'content-type' => $post_mime_type
			),
			'body'        => $bits,
			'cookies'     => array(),
			'user-agent'  => sprintf( 'WordPress/%s', $GLOBALS['wp_version'] ),
		) );
		$response = wp_remote_post( $export->to, $args );
		if( is_wp_error( $response ) ) {
			error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $response->get_error_message() ) );
			return false;
		} else {
			error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Remote POST sent to %s', 'woo_ce' ), $export->to ) ) );
		}
	// Output to screen in friendly design with on-screen error responses
	} else if( $gui == 'gui' ) {
		if( file_exists( WOO_CD_PATH . 'templates/admin/cron.php' ) ) {
			include_once( WOO_CD_PATH . 'templates/admin/cron.php' );
		} else {
			error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load template file within /templates/admin/cron.php', 'woo_ce' ) ) );
		}
		if( isset( $output ) )
			echo $output;
		echo '
	</body>
</html>';
	// Save export file to WordPress Media before sending/saving/etc. action
	} else if( in_array( $gui, array( 'gui', 'archive', 'url', 'file', 'email', 'ftp' ) ) ) {
		$upload = false;
		if( $export->filename && !empty( $bits ) ) {
			$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
			$upload = wp_upload_bits( $export->filename, null, $bits );
			if( ( $post_ID == false ) || $upload['error'] ) {
				wp_delete_attachment( $post_ID, true );
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $upload['error'] ) );
				return false;
			}
			if( file_exists( ABSPATH . 'wp-admin/includes/image.php' ) ) {
				include_once( ABSPATH . 'wp-admin/includes/image.php' );
				$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
				wp_update_attachment_metadata( $post_ID, $attach_data );
				update_attached_file( $post_ID, $upload['file'] );
				if( !empty( $post_ID ) ) {
					woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
					woo_ce_save_file_details( $post_ID );
				}
			} else {
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load image.php within /wp-admin/includes/image.php', 'woo_ce' ) ) );
			}
		}
		// Return URL to export file
		if( $gui == 'url' )
			return $upload['url'];
		// Return system path to export file
		if( $gui == 'file' )
			return $upload['file'];
		// E-mail export file to preferred address or WordPress site owner address
		if( $gui == 'email' ) {

			global $woocommerce;

			$mailer = $woocommerce->mailer();
			$subject = woo_ce_cron_email_subject( $export->type, $export->filename );
			$attachment = $upload['file'];
			$email_heading = sprintf( __( 'Export: %s', 'woo_ce' ), ucwords( $export->type ) );
			$recipient_name = apply_filters( 'woo_ce_email_recipient_name', __( 'there', 'woo_ce' ) );
			$email_contents = apply_filters( 'woo_ce_email_contents', wpautop( __( 'Please find attached your export ready to review.', 'woo_ce' ) ) );

			// Buffer
			ob_start();

			// Get mail template
			if( file_exists( WOO_CD_PATH . 'templates/emails/scheduled_export.php' ) ) {
				include_once( WOO_CD_PATH . 'templates/emails/scheduled_export.php' );
			} else {
				echo wpautop( sprintf( __( 'Hi %s', 'woo_ce' ), $recipient_name ) );
				echo $email_contents;
				error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, sprintf( __( 'Could not load template file %s within %s, defaulted to hard coded template.', 'woo_ce' ), 'scheduled_export.php', '/templates/emails/...' ) ) );
			}

			// Get contents
			$message = ob_get_clean();

			// Send the mail using WooCommerce mailer
			if( function_exists( 'woocommerce_mail' ) ) {
				woocommerce_mail( $export->to, $subject, $message, null, $attachment );
			} else {
				// Default to wp_mail()
				add_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
				wp_mail( $export->to, $subject, $message, null, $attachment );
				remove_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
			}
			// Delete the export file regardless of whether e-mail was successful or not
			wp_delete_attachment( $post_ID, true );
			error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export e-mail of %s sent to %s', 'woo_ce' ), $export->filename, $export->to ) ) );

		}
		if( $gui == 'ftp' ) {

			// Load up our FTP/SFTP resources
			$host = woo_ce_get_option( 'auto_ftp_method_host', '' );
			if( !empty( $host ) )
				$host = woo_ce_format_ftp_host( $host );
			$port = woo_ce_get_option( 'auto_ftp_method_port', '' );
			$port = ( !empty( $port ) ? absint( $port ) : false );
			$user = woo_ce_get_option( 'auto_ftp_method_user', '' );
			$pass = woo_ce_get_option( 'auto_ftp_method_pass', '' );
			$path = woo_ce_get_option( 'auto_ftp_method_path', '' );
			$filename = woo_ce_get_option( 'auto_ftp_method_filename', '' );
			// Switch to fixed export filename if provided
			if( !empty( $filename ) )
				$export->filename = woo_ce_generate_filename( $export->type, $filename ) . '.' . $file_extension;

			// Check what protocol are we using; FTP or SFTP?
			$protocol = woo_ce_get_option( 'auto_ftp_method_protocol', 'ftp' );
			switch( $protocol ) {

				case 'ftp':
				default:
					// Check if ftp_connect() is available
					if( function_exists( 'ftp_connect' ) ) {
						$passive = woo_ce_get_option( 'auto_ftp_method_passive', '' );
						$timeout = woo_ce_get_option( 'auto_ftp_method_timeout', '' );
						if( $connection = @ftp_connect( $host, $port ) ) {
							// Update the FTP timeout if available and if a timeout was provided at export
							$remote_timeout = ftp_get_option( $connection, FTP_TIMEOUT_SEC );
							$timeout = absint( $timeout );
							if( $remote_timeout !== false && !empty( $timeout ) ) {
								// Compare the server timeout and the timeout provided at export
								if( $remote_timeout <> $timeout ) {
									if( ftp_set_option( $connection, FTP_TIMEOUT_SEC, $timeout ) == false )
										error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', $export->filename, sprintf( __( 'Could not change the FTP server timeout on %s', 'woo_ce' ), $host ) ) );
								}
							}
							unset( $remote_timeout );
							if( ftp_login( $connection, $user, $pass ) ) {
								// Check if Transfer Mode is set to Auto/Pasive and if passive mode is available
								if( in_array( $passive, array( 'auto', 'passive' ) ) ) {
									$features = ftp_raw( $connection, 'FEAT' );
									if( !empty( $features ) ) {
										if( in_array( 'PASV', $features ) ) {
											if( ftp_pasv( $connection, true ) == false )
												error_log( sprintf( '[store-exporter-deluxe] %s: Warning: %s', 'woo_ce', $export->filename, sprintf( __( 'Could not switch to FTP passive mode on %s', 'woo_ce' ), $host ) ) );
										}
									}
								}
								// Change directory if neccesary
								if( !empty( $directory ) ) {
									$current_directory  = ftp_pwd( $connection );
									if( $current_directory !== false && @ftp_chdir( $connection, $path ) )
										ftp_chdir( $connection, $path );
								}
								if( ftp_put( $connection, sprintf( '%s/%s', $path, $export->filename ), $upload['file'], FTP_ASCII ) ) {
									error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export of %s to %s via FTP uploaded', 'woo_ce' ), $export->filename, $path ) ) );
								} else {
									$export->error = sprintf( __( 'There was a problem uploading %s to %s via FTP, response: %s', 'woo_ce' ), $export->filename, $path, woo_ce_error_get_last_message() );
									error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
								}
							} else {
								$export->error = sprintf( __( 'Login incorrect for user %s on FTP server at %s, response: %s', 'woo_ce' ), $user, $host, woo_ce_error_get_last_message() );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
							}
						} else {
							$export->error = sprintf( __( 'There was a problem connecting to %s via FTP', 'woo_ce' ), $host );
							error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
						}
					} else {
						$export->error = __( 'The function ftp_connect() is disabled within your WordPress site, cannot upload to FTP server', 'woo_ce' );
						error_log( __( '[store-exporter-deluxe] %s: Error: %s', 'woo_ce' ), $export->filename, $export->error );
					}
					break;

				case 'sftp':
					// Check if ssh2_connect() is available
					if( function_exists( 'ssh2_connect' ) ) {
						if( $connection = @ssh2_connect( $host, $port ) ) {
							if( ssh2_auth_password( $connection, $user, $pass ) ) {
								// Initialize SFTP subsystem
								if( $session = ssh2_sftp( $connection ) ) {
									if( $handle = fopen( sprintf( 'ssh2.sftp://%s/%s/%s', $session, $path, $export->filename ), 'w+' ) ) {
										error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Scheduled export of %s to %s via SFTP uploaded', 'woo_ce' ), $export->filename, $path ) ) );
									} else {
										$export->error = sprintf( __( 'There was a problem uploading %s to %s via SFTP', 'woo_ce' ), $export->filename, $path );
										error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
									}
								} else {
									$export->error = sprintf( __( 'Could not initialize SFTP subsystem on SFTP server at %s', 'woo_ce' ), $host );
									error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
								}
							} else {
								$export->error = sprintf( __( 'Login incorrect for user %s on SFTP server at %s', 'woo_ce' ), $user, $host );
								error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
							}
						} else {
							$export->error = sprintf( __( 'There was a problem connecting to %s via SFTP', 'woo_ce' ), $host );
							error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $export->error ) );
						}
					} else {
						$export->error = __( 'The function ssh2_connect() is disabled within your WordPress site, cannot upload to SFTP server', 'woo_ce' );
						error_log( sprintf( __( '[store-exporter-deluxe] %s: Error: %s', 'woo_ce' ), $export->filename, $export->error ) );
					}
					break;

			}
			// Delete the export file regardless of whether upload was successful or not
			wp_delete_attachment( $post_ID, true );
		}
	}

	// Only include scheduled exports to the Recent Scheduled Exports list
	if( $export->scheduled_export ) {
		$recent_exports = woo_ce_get_option( 'recent_scheduled_exports', array() );
		if( empty( $recent_exports ) )
			$recent_exports = array();
		$size = count( $recent_exports );
		// Get the limit from the WordPress Dashboard widget
		if( !$widget_options = get_option( 'woo_ce_recent_scheduled_export_widget_options', array() ) ) {
			$widget_options = array(
				'number' => 5
			);
		}

		// Check if we have maxed out our recent scheduled exports
		if( $size >= $widget_options['number'] )
			array_shift( $recent_exports );
		$post_ID = ( isset( $post_ID ) ? $post_ID : 0 );
		$recent_exports[] = array(
			'post_id' => ( empty( $export->error ) ? $post_ID : 0 ),
			'name' => $export->filename,
			'date' => time(),
			'method' => $gui,
			'error' => $export->error
		);
		woo_ce_update_option( 'recent_scheduled_exports', $recent_exports );
	}

	delete_option( WOO_CD_PREFIX . '_exported' );

	// If the CRON process gets this far, pass on the good news!
	return true;

}
 /**
  * Function to send invoice as email
  */
 function woocommerce_pip_send_email($order_id)
 {
     if (get_option('woocommerce_pip_send_email') == 'enabled') {
         // Build email information
         $order = new WC_Order($order_id);
         $to = $order->billing_email;
         $subject = __('Order invoice', 'woocommerce-pip');
         $subject = '[' . get_bloginfo('name') . '] ' . $subject;
         $attachments = '';
         // Read the file
         ob_start();
         require_once woocommerce_pip_template('dir', 'email-template.php') . 'email-template.php';
         $message = ob_get_clean();
         // Send the mail
         woocommerce_mail($to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments);
     }
 }
Esempio n. 6
0
 function ac_email_admin_recovery($order_id)
 {
     $user_id = get_current_user_id();
     $cart_ac_settings = json_decode(get_option('woocommerce_ac_settings'));
     if ($cart_ac_settings[0]->email_admin == 'on') {
         if (get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("yes") || get_user_meta($user_id, '_woocommerce_ac_modified_cart', true) == md5("no")) {
             $order = new WC_Order($order_id);
             $email_heading = __('New Customer Order - Recovered', 'woocommerce');
             $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
             $email_subject = "New Customer Order - Recovered";
             $user_email = get_option('admin_email');
             $headers[] = "From: Admin <" . $user_email . ">";
             $headers[] = "Content-Type: text/html";
             // Buffer
             ob_start();
             // Get mail template
             woocommerce_get_template('emails/admin-new-order.php', array('order' => $order, 'email_heading' => $email_heading));
             // Get contents
             $email_body = ob_get_clean();
             //$email_body .= "Recovered Order";
             woocommerce_mail($user_email, $email_subject, $email_body, $headers);
         }
     }
 }
Esempio n. 7
0
 /**
  * Successful Payment!
  **/
 function successful_request($posted)
 {
     // Custom holds post ID
     if (!empty($posted['custom']) && !empty($posted['invoice'])) {
         $order = new WC_Order((int) $posted['custom']);
         if ($order->order_key !== $posted['invoice']) {
             if ($this->debug == 'yes') {
                 $this->log->add('paypal', 'Error: Order Key does not match invoice.');
             }
             exit;
         }
         // Lowercase
         $posted['payment_status'] = strtolower($posted['payment_status']);
         $posted['txn_type'] = strtolower($posted['txn_type']);
         // Sandbox fix
         if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending') {
             $posted['payment_status'] = 'completed';
         }
         if ($this->debug == 'yes') {
             $this->log->add('paypal', 'Payment status: ' . $posted['payment_status']);
         }
         // We are here so lets check status and do actions
         switch ($posted['payment_status']) {
             case 'completed':
                 // Check order not already completed
                 if ($order->status == 'completed') {
                     if ($this->debug == 'yes') {
                         $this->log->add('paypal', 'Aborting, Order #' . $posted['custom'] . ' is already complete.');
                     }
                     exit;
                 }
                 // Check valid txn_type
                 $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money');
                 if (!in_array($posted['txn_type'], $accepted_types)) {
                     if ($this->debug == 'yes') {
                         $this->log->add('paypal', 'Aborting, Invalid type:' . $posted['txn_type']);
                     }
                 }
                 // Store PP Details
                 update_post_meta((int) $posted['custom'], 'Payer PayPal address', $posted['payer_email']);
                 update_post_meta((int) $posted['custom'], 'Transaction ID', $posted['txn_id']);
                 update_post_meta((int) $posted['custom'], 'Payer first name', $posted['first_name']);
                 update_post_meta((int) $posted['custom'], 'Payer last name', $posted['last_name']);
                 update_post_meta((int) $posted['custom'], 'Payment type', $posted['payment_type']);
                 // Payment completed
                 $order->add_order_note(__('IPN payment completed', 'woocommerce'));
                 $order->payment_complete();
                 if ($this->debug == 'yes') {
                     $this->log->add('paypal', 'Payment complete.');
                 }
                 break;
             case 'denied':
             case 'expired':
             case 'failed':
             case 'voided':
                 // Order failed
                 $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                 break;
             case "refunded":
                 // Only handle full refunds, not partial
                 if ($order->get_order_total() == $posted['mc_gross'] * -1) {
                     // Mark order as refunded
                     $order->update_status('refunded', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                     $message = woocommerce_mail_template(__('Order refunded/reversed', 'woocommerce'), sprintf(__('Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce'), $order->id, $posted['reason_code']));
                     // Send the mail
                     woocommerce_mail(get_option('woocommerce_new_order_email_recipient'), sprintf(__('Payment for order #%s refunded/reversed', 'woocommerce'), $order->id), $message);
                 }
                 break;
             case "reversed":
             case "chargeback":
                 // Mark order as refunded
                 $order->update_status('refunded', sprintf(__('Payment %s via IPN.', 'woocommerce'), strtolower($posted['payment_status'])));
                 $message = woocommerce_mail_template(__('Order refunded/reversed', 'woocommerce'), sprintf(__('Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce'), $order->id, $posted['reason_code']));
                 // Send the mail
                 woocommerce_mail(get_option('woocommerce_new_order_email_recipient'), sprintf(__('Payment for order #%s refunded/reversed', 'woocommerce'), $order->id), $message);
                 break;
             default:
                 // No action
                 break;
         }
         exit;
     }
 }
 public function send_verification($to, $un, $pw, $hash)
 {
     global $wpdb, $wp_version;
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $headers = "Content-Type: text/htmlrn";
     $subject = 'Activate your ' . $blogname . ' account';
     $message = 'Hello ' . $un . ',<br/><br/>';
     $message .= 'To activate your account and access the feature you were trying to view, copy and paste the following link into your web browser:';
     $message .= "<br/>";
     $message .= home_url('/') . 'activate?id=' . $un . '&passkey=' . $hash;
     $message .= "<br/><br/>";
     $message .= "Thank you for registering with us.";
     $message .= '<br/><br/>Yours sincerely,<br/>' . $blogname;
     woocommerce_mail($to, $subject, $message, $headers, $attachments);
     return;
 }
 /** AJAX ************************************************************/
 function lost_licence_ajax()
 {
     global $woocommerce, $wpdb;
     check_ajax_referer('wc-lost-licence', 'security');
     $email = esc_attr(trim($_POST['email']));
     if (!is_email($email)) {
         die(json_encode(array('success' => false, 'message' => __('Invalid Email Address', 'wc_software'))));
     }
     $licence_keys = $wpdb->get_results("\n\t\t\t\tSELECT * FROM {$wpdb->prefix}woocommerce_software_licences\n\t\t\t\tWHERE activation_email = '{$email}'\n\t\t\t");
     if (sizeof($licence_keys) > 0) {
         ob_start();
         $mailer = $woocommerce->mailer();
         woocommerce_get_template('email-lost-keys.php', array('keys' => $licence_keys, 'email_heading' => __('Your licence keys', 'wc_software')), 'woocommerce-software', $this->plugin_path() . '/templates/');
         $message = ob_get_clean();
         woocommerce_mail($email, __('Your licence keys', 'wc_software'), $message);
         die(json_encode(array('success' => true, 'message' => __('Your licence keys have been emailed', 'wc_software'))));
     } else {
         die(json_encode(array('success' => false, 'message' => __('No licence keys were found for your email address', 'wc_software'))));
     }
 }
 function sa_email_coupon($coupon_title, $discount_type, $gift_certificate_receiver_name = '', $message_from_sender = '', $gift_certificate_sender_name = '', $gift_certificate_sender_email = '')
 {
     global $woocommerce;
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $subject_string = __("Congratulations! You've received a coupon", 'wc_smart_coupons');
     $url = get_option('permalink_structure') ? get_permalink(woocommerce_get_page_id('shop')) : get_post_type_archive_link('product');
     if ($discount_type == 'smart_coupon' && ($gift_certificate_sender_name != '' || $gift_certificate_sender_email != '')) {
         $from = $gift_certificate_sender_name != '' ? $gift_certificate_sender_name . ' ( ' . $gift_certificate_sender_email . ' )' : substr($gift_certificate_sender_email, 0, strpos($gift_certificate_sender_email, '@'));
         $subject_string .= ' ' . __('from', 'wc_smart_coupons') . ' ' . $from;
     }
     $subject_string = get_option('smart_coupon_email_subject') && get_option('smart_coupon_email_subject') != '' ? __(get_option('smart_coupon_email_subject'), 'wc_smart_coupons') : $subject_string;
     $subject = apply_filters('woocommerce_email_subject_gift_certificate', sprintf('[%s] %s', $blogname, $subject_string));
     foreach ($coupon_title as $email => $coupon) {
         $amount = $coupon['amount'];
         $coupon_code = $coupon['code'];
         switch ($discount_type) {
             case 'smart_coupon':
                 $email_heading = sprintf(__('You have received credit worth %s ', 'wc_smart_coupons'), woocommerce_price($amount));
                 break;
             case 'fixed_cart':
                 $email_heading = sprintf(__('You have received a coupon worth %s (on entire purchase) ', 'wc_smart_coupons'), woocommerce_price($amount));
                 break;
             case 'fixed_product':
                 $email_heading = sprintf(__('You have received a coupon worth %s (for a product) ', 'wc_smart_coupons'), woocommerce_price($amount));
                 break;
             case 'percent_product':
                 $email_heading = sprintf(__('You have received a coupon worth %s%% (for a product) ', 'wc_smart_coupons'), $amount);
                 break;
             case 'percent':
                 $email_heading = sprintf(__('You have received a coupon worth %s%% (on entire purchase) ', 'wc_smart_coupons'), $amount);
                 break;
         }
         // Buffer
         ob_start();
         include apply_filters('woocommerce_gift_certificates_email_template', 'templates/email.php');
         // Get contents of the e-mail to be sent
         $message = ob_get_clean();
         woocommerce_mail($email, $subject, $message);
     }
 }