Settings > Emails. */ abstract class Email extends \WC_Email { /** * Affiliate row in context for the current send. * * @var object|null */ protected $affiliate = null; /** * Notification preference that switches this email off for an * affiliate, or empty when the email is always sent. * * @var string */ protected $pref_type = ''; /** * Returns the affiliate repository. * * @since 1.0.0 * @return \PPL_AFW\Affiliates\Affiliate_Repository */ protected function affiliates() { return ppl_afw()->container->get( 'affiliates.repository' ); } /** * HTML body, wrapped in the WooCommerce email header and footer. * * @since 1.0.0 * @return string */ public function get_content_html() { ob_start(); wc_get_template( 'emails/email-header.php', array( 'email_heading' => $this->get_heading(), 'email' => $this, ) ); echo wp_kses_post( wpautop( wptexturize( $this->get_body() ) ) ); wc_get_template( 'emails/email-footer.php', array( 'email' => $this ) ); return ob_get_clean(); } /** * Plain text body. * * @since 1.0.0 * @return string */ public function get_content_plain() { return wp_strip_all_tags( $this->get_body() ); } /** * The dashboard link shown at the end of affiliate facing emails. * * @since 1.0.0 * @return string */ protected function dashboard_link() { $page_id = (int) ppl_afw()->container->get( 'settings' )->get( 'portal_page_id' ); $url = $page_id ? get_permalink( $page_id ) : home_url( '/' ); return '
' . esc_html__( 'Open your affiliate dashboard', 'affireo-affiliates-for-woocommerce' ) . '
'; } /** * The email body content. Concrete emails implement this. * * @since 1.0.0 * @return string */ abstract protected function get_body(); /** * Sends this email to its resolved recipient when enabled. * * @since 1.0.0 */ protected function dispatch() { if ( '' !== $this->pref_type && $this->affiliate && ! ppl_afw()->container->get( 'notifications' )->wants( (int) $this->affiliate->id, $this->pref_type ) ) { return; // The affiliate switched this email off in their dashboard. } if ( $this->is_enabled() && $this->get_recipient() ) { $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); } } }