mailer()->get_emails();
return isset( $emails[ $key ] ) ? $emails[ $key ] : null;
}
/**
* Send both emails right after a submission.
*
* @param Submission $submission Submission.
* @param \WC_Order $order Order.
*/
public static function send_for_submission( $submission, $order ) {
self::send_customer( $submission, $order );
$admin = self::email( 'PY_Otkaz_Admin_Notification' );
if ( ! $admin || ! $admin->is_enabled() || ! $admin->get_recipient() ) {
$submission->update_email_status( '', 'disabled' );
return;
}
$sent = (bool) $admin->trigger( $submission, $order );
$submission->update_email_status( '', $sent ? 'sent' : 'failed' );
if ( ! $sent ) {
wc_get_logger()->error( sprintf( 'Store notification for %s could not be sent.', $submission->number ), array( 'source' => 'otkazpro' ) );
}
}
/**
* Send (or resend) the customer confirmation and record the result.
*
* @param Submission $submission Submission.
* @param \WC_Order|null $order Order.
* @return bool
*/
public static function send_customer( $submission, $order = null ) {
$order = $order ? $order : Verifier::get_order( $submission->order_id );
$email = self::email( 'PY_Otkaz_Customer_Confirmation' );
$sent = false;
if ( $email && $order ) {
$state = I18n::switch_to_order_language( $order, $submission->language );
try {
$sent = (bool) $email->trigger( $submission, $order );
} finally {
I18n::restore( $state );
}
}
$submission->update_email_status( $sent ? 'sent' : 'failed' );
if ( ! $sent ) {
wc_get_logger()->error(
sprintf( 'Withdrawal confirmation %s could not be sent to %s (wp_mail returned false).', $submission->number, $submission->email ),
array( 'source' => 'otkazpro' )
);
/**
* Fires when the customer confirmation email fails.
*
* @param Submission $submission Submission.
*/
do_action( 'py_otkaz_mail_failed', $submission );
}
return $sent;
}
/**
* Link block in WooCommerce customer order emails (standard template hook).
*
* @param \WC_Order $order Order.
* @param bool $sent_to_admin Admin email.
* @param bool $plain_text Plain text.
* @param \WC_Email $email Email.
*/
public static function order_email_link( $order, $sent_to_admin = false, $plain_text = false, $email = null ) {
if ( $sent_to_admin ) {
return;
}
echo wp_kses_post( self::link_block( $order, $email, (bool) $plain_text ) );
}
/**
* Fallback for email customizers (VillaTheme, YayMail, Kadenceā¦) that replace the
* WooCommerce templates without firing woocommerce_email_after_order_table:
* append the block to the final message if it is not there yet.
*
* @param array $params [to, subject, message, headers, attachments].
* @param \WC_Email $email Email.
* @return array
*/
public static function ensure_link_in_message( $params, $email = null ) {
if ( ! $email instanceof \WC_Email || ! isset( $params[2] ) || ! is_string( $params[2] ) ) {
return $params;
}
if ( ! apply_filters( 'py_otkaz_email_link_fallback', true, $email ) ) {
return $params;
}
$order = $email->object;
if ( ! $order instanceof \WC_Order ) {
return $params;
}
$plain = 'plain' === $email->get_email_type();
$message = $params[2];
$url = Form::order_url( $order, I18n::order_language( $order ) );
if ( preg_match( '/(otkazpro|wpotkaz|py-otkaz)-email-link/', $message ) || false !== strpos( $message, esc_url( $url ) ) || false !== strpos( $message, $url ) ) {
return $params;
}
$block = self::link_block( $order, $email, $plain );
if ( '' === $block ) {
return $params;
}
if ( $plain ) {
// The message is already final here, so undo esc_url()'s & as WooCommerce does for plain emails.
$params[2] = rtrim( $message ) . "
" . str_replace( '&', '&', trim( $block ) ) . "
";
return $params;
}
$block = '
';
$pos = strripos( $message, '