|  | 
 | <?php
  | 
 | add_action( 'init', function() {
  | 
 | 
  | 
 | 	if ( ! class_exists( '\EDD\Emails\Types\Email' ) ) {
  | 
 | 		return;
  | 
 | 	}
  | 
 | 
  | 
 | 	
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 	class EDDWP_PreApproved_Email extends \EDD\Emails\Types\Email {
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected $id = 'preapproved';
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected $context = 'order';
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected $recipient_type = 'customer';
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected $order;
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected $order_id;
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		public function __construct( $order ) {
  | 
 | 			$this->order = $order;
  | 
 | 
  | 
 | 			
  | 
 | 			$this->order_id = false !== $order ? $order->id : 0;
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		public function get_order() {
  | 
 | 			return $this->order;
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_email_body_content() {
  | 
 | 			$this->raw_body_content = $this->get_default_body_content();
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_from_name() {
  | 
 | 			$this->from_name = edd_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_from_email() {
  | 
 | 			$this->from_email = edd_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_to_email() {
  | 
 | 			if ( empty( $this->send_to ) && ! empty( $this->order->email ) ) {
  | 
 | 				$this->send_to = $this->order->email;
  | 
 | 			}
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_headers() {
  | 
 | 			$this->headers = $this->processor()->get_headers();
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_subject() {
  | 
 | 			$this->subject = __( 'Thank you for your Pre-Sale Order', 'easy-digital-downloads' );
  | 
 | 			$this->subject = wp_strip_all_tags( $this->process_tags( $this->subject, $this->order_id ) );
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_heading() {
  | 
 | 			$this->heading = __( 'Preapproved Payment Confirmation', 'easy-digital-downloads' );
  | 
 | 			$this->heading = $this->process_tags( $this->heading, $this->order_id );
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_message() {
  | 
 | 			$message = $this->get_raw_body_content();
  | 
 | 
  | 
 | 			$this->message = $this->process_tags( $this->maybe_apply_autop( $message ), $this->order_id );
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function set_attachments() {
  | 
 | 			$this->attachments = array();
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		public function get_default_body_content() {
  | 
 | 			$default_email_body  = __( 'Dear', 'easy-digital-downloads' ) . " {name},\n\n";
  | 
 | 			$default_email_body .= __( 'Your pre-order has been received. Your payment method has not been charged yet, however you may see a pending authorization on your statement. You payment will be charged once the pre-order period is over.', 'easy-digital-downloads' ) . "\n\n";
  | 
 | 			$default_email_body .= 'Pre-Sale Price: {price}' . "\n\n";
  | 
 | 			$default_email_body .= '{sitename}';
  | 
 | 
  | 
 | 			return $default_email_body;
  | 
 | 		}
  | 
 | 
  | 
 | 		
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 
  | 
 | 		protected function should_send() {
  | 
 | 			
  | 
 | 			if ( true === apply_filters( 'edd_disable_' . $this->id, false, $this ) ) {
  | 
 | 				return false;
  | 
 | 			}
  | 
 | 
  | 
 | 			return true;
  | 
 | 		}
  | 
 | 	}
  | 
 | 
  | 
 | 	
  | 
 | 	EDD\Emails\Registry::register( 'preapproved', 'EDDWP_PreApproved_Email' );
  | 
 | } );
  | 
 | 
  | 
 | add_action( 'edd_transition_order_status', function( $old_status, $new_status, $order_id  ) {
  | 
 | 	
  | 
 | 	if ( ! class_exists( '\EDD\Emails\Types\Email' ) ) {
  | 
 | 		return;
  | 
 | 	}
  | 
 | 
  | 
 | 	
  | 
 | 	edd_debug_log( 'transition_order_status: ' . $old_status . ' -> ' . $new_status );
  | 
 | 	if ( 'preapproval' !== $new_status ) {
  | 
 | 		return;
  | 
 | 	}
  | 
 | 
  | 
 | 	$order = edd_get_order( $order_id );
  | 
 | 
  | 
 | 	
  | 
 | 	$email = new EDDWP_PreApproved_Email( $order );
  | 
 | 	$email->send();
  | 
 | }, 99, 3 );
  | 
 |  | 
 |  | 
Comments