Settings > Emails, * so existing stores receive no new email after updating. */ class Admin_Referral_Email extends Email { /** * Referral row for the current send. * * @var object|null */ protected $referral = null; /** * Order for the current send. * * @var \WC_Order|null */ protected $order = null; /** * Constructor. */ public function __construct() { $this->id = 'ppl_afw_admin_new_referral'; $this->title = __( 'New referral (admin)', 'affireo-affiliates-for-woocommerce' ); $this->description = __( 'Sent to the store admin when an order is credited to an affiliate. Off by default.', 'affireo-affiliates-for-woocommerce' ); $this->heading = __( 'New affiliate referral', 'affireo-affiliates-for-woocommerce' ); $this->subject = __( 'An affiliate referred a new order', 'affireo-affiliates-for-woocommerce' ); $this->recipient = get_option( 'admin_email' ); add_action( 'ppl_afw_referral_created', array( $this, 'trigger' ), 20, 3 ); parent::__construct(); } /** * Form fields, with the email disabled until the store owner opts in. * * @since 1.1.0 */ public function init_form_fields() { parent::init_form_fields(); if ( isset( $this->form_fields['enabled'] ) ) { $this->form_fields['enabled']['default'] = 'no'; } } /** * Triggers the email. * * @since 1.1.0 * @param int $referral_id Referral id. * @param object $affiliate Affiliate row. * @param \WC_Order $order Order object. */ public function trigger( $referral_id, $affiliate, $order ) { if ( ! $this->is_enabled() ) { return; } $this->setup_locale(); $this->affiliate = $affiliate; $this->order = $order instanceof \WC_Order ? $order : null; $this->referral = ppl_afw()->container->get( 'referrals.repository' )->find( $referral_id ); if ( ! $this->get_recipient() ) { $this->recipient = get_option( 'admin_email' ); } if ( $this->referral ) { $this->dispatch(); } $this->restore_locale(); } /** * Body content. * * @since 1.1.0 * @return string */ protected function get_body() { $user = $this->affiliate ? get_userdata( (int) $this->affiliate->user_id ) : null; $currency = $this->referral ? (string) $this->referral->currency : ''; $args = $currency ? array( 'currency' => $currency ) : array(); $body = '

' . esc_html__( 'A new order was credited to one of your affiliates. The commission is pending until its review period ends.', 'affireo-affiliates-for-woocommerce' ) . '

'; if ( $user ) { $body .= '

' . esc_html__( 'Affiliate:', 'affireo-affiliates-for-woocommerce' ) . ' ' . esc_html( $user->display_name . ' (' . $user->user_email . ')' ) . '

'; } if ( $this->order ) { $body .= '

' . esc_html__( 'Order:', 'affireo-affiliates-for-woocommerce' ) . ' #' . esc_html( $this->order->get_order_number() ) . '

'; } if ( $this->referral ) { $body .= '

' . esc_html__( 'Commission:', 'affireo-affiliates-for-woocommerce' ) . ' ' . wp_kses_post( wc_price( (float) $this->referral->amount, $args ) ) . '

'; $body .= '

' . esc_html__( 'Commission basis:', 'affireo-affiliates-for-woocommerce' ) . ' ' . wp_kses_post( wc_price( (float) $this->referral->base_amount, $args ) ) . '

'; } $body .= '

' . esc_html__( 'Review referrals', 'affireo-affiliates-for-woocommerce' ) . '

'; return $body; } }