get_row($wpdb->prepare( "SELECT * FROM {$wpdb->prefix}aieo_dmm_withdrawal_declarations WHERE id = %d", (int) $declaration_id )); if (!$row) { return; } $declared_ts = strtotime($row->declared_at_gmt . ' UTC'); $stamp = wp_date( get_option('date_format') . ', ' . get_option('time_format'), $declared_ts ); $subject = sprintf( __('Withdrawal confirmation — order %s', 'ai-eshop-optimizer'), $order->get_order_number() ); $body = '
' . esc_html__('We confirm that we have received your withdrawal declaration. Keep this email as your receipt.', 'ai-eshop-optimizer') . '
'; $body .= '' . esc_html__('Items covered by this withdrawal', 'ai-eshop-optimizer') . '
'; $body .= '' . esc_html__('Your note', 'ai-eshop-optimizer') . ': ' . esc_html($row->reason_note) . '
'; } $body .= !empty($context['cancelled']) ? '' . esc_html__('Your order has been cancelled. Any amount already paid will be refunded to the original payment method.', 'ai-eshop-optimizer') . '
' : '' . esc_html__('We are processing your withdrawal and will contact you shortly about returning the items and refunding you.', 'ai-eshop-optimizer') . '
'; $body .= self::account_block($context); if (class_exists('AIEO_Withdrawal_Account')) { $body .= AIEO_Withdrawal_Account::contact_block(); } if (class_exists('AIEO_Withdrawal_Guest')) { AIEO_Withdrawal_Guest::mail($order->get_billing_email(), $subject, $body); } AIEO_Withdrawal::mark_acknowledged($declaration_id); } private static function account_block(array $context) { $account = isset($context['account']) && is_array($context['account']) ? $context['account'] : array(); if (empty($account['created'])) { return ''; } if (!class_exists('AIEO_Withdrawal_Account')) { return ''; } $lines = AIEO_Withdrawal_Account::account_created_lines( (int) ($account['linked'] ?? 1), !empty($account['magic_link']) ); if (empty($lines)) { return ''; } $html = '' . esc_html($line) . '
'; } $html .= '' . esc_html__('We have approved your return. We are arranging the collection and will be in touch with the details shortly.', 'ai-eshop-optimizer') . '
'; if ($has_voucher) { $body .= '' . esc_html(sprintf( __('Your return reference: %s', 'ai-eshop-optimizer'), (string) $row->return_voucher_no )) . '
'; } if (class_exists('AIEO_Withdrawal_Account')) { $body .= AIEO_Withdrawal_Account::contact_block(); } if (class_exists('AIEO_Withdrawal_Guest')) { AIEO_Withdrawal_Guest::mail($to, $subject, $body); } return; } $url = AIEO_Withdrawal_Account::signed_label_url($row, $order); $body = '' . esc_html__('Your return label is ready. Print it, attach it to the parcel, and hand it to the courier.', 'ai-eshop-optimizer') . '
'; $body .= '' . esc_html__('Download the label', 'ai-eshop-optimizer') . '
'; $body .= '' . esc_html(sprintf( __('Courier: %1$s · Voucher: %2$s', 'ai-eshop-optimizer'), (string) $row->return_carrier, (string) $row->return_voucher_no )) . '
'; $body .= '' . esc_html__('It is also on your order page in your account, any time you need it again.', 'ai-eshop-optimizer') . '
'; $party = AIEO_Withdrawal_Returns::policy(); if ('recipient' === $party['charge_party']) { $body .= '' . esc_html__('The return costs you nothing — we are paying the courier.', 'ai-eshop-optimizer') . '
'; } if (class_exists('AIEO_Withdrawal_Guest')) { AIEO_Withdrawal_Guest::mail($to, $subject, $body); } } public static function add_store_email($emails) { if (!is_array($emails) || !class_exists('WC_Email')) { return $emails; } if (!class_exists('AIEO_Email_Withdrawal_Request')) { $file = __DIR__ . '/class-aieo-email-withdrawal-request.php'; if (!file_exists($file)) { return $emails; } require_once $file; } if (class_exists('AIEO_Email_Withdrawal_Request')) { $emails['AIEO_Email_Withdrawal_Request'] = new AIEO_Email_Withdrawal_Request(); } return $emails; } public static function send_rejection($row, $order = null) { if (!class_exists('AIEO_Withdrawal_Guest')) { return false; } $to = ''; if ($order instanceof WC_Order) { $to = (string) $order->get_billing_email(); } if (!is_email($to) && !empty($row->billing_email)) { $to = (string) $row->billing_email; } if (!is_email($to)) { return false; } $sent = false; AIEO_Withdrawal_Guest::in_shop_language(static function () use ($row, $order, $to, &$sent) { $grounds = array(); if (class_exists('AIEO_Withdrawal_Rejection_Reasons')) { $ids = json_decode((string) ($row->rejection_reasons ?? ''), true); $grounds = AIEO_Withdrawal_Rejection_Reasons::labels_for_customer(is_array($ids) ? $ids : array()); } $order_no = ($order instanceof WC_Order) ? $order->get_order_number() : (string) ($row->order_id ?? ''); $subject = sprintf( __('About your withdrawal request for order %s', 'ai-eshop-optimizer'), $order_no ); $body = '' . esc_html__('We have looked at your withdrawal request and we are not able to accept it.', 'ai-eshop-optimizer') . '
'; if ($grounds) { $body .= '' . esc_html__('This is because:', 'ai-eshop-optimizer') . '
' . esc_html((string) $row->rejection_note) . '
'; } $body .= '' . esc_html__('If you think this is wrong, reply to this email and we will look at it again.', 'ai-eshop-optimizer') . '
'; if (class_exists('AIEO_Withdrawal_Account')) { $body .= AIEO_Withdrawal_Account::contact_block(); } AIEO_Withdrawal_Guest::mail($to, $subject, $body); $sent = true; }); return $sent; } public static function send_store_notification($declaration_id, $order, array $context) { if (!$order instanceof WC_Order) { return; } if (!empty($context['cancelled'])) { return; } if (!function_exists('WC') || !WC()->mailer()) { return; } if (!class_exists('AIEO_Withdrawal_Guest')) { return; } AIEO_Withdrawal_Guest::in_shop_language(static function () use ($declaration_id, $order, $context) { try { $emails = WC()->mailer()->get_emails(); if (isset($emails['AIEO_Email_Withdrawal_Request'])) { $emails['AIEO_Email_Withdrawal_Request']->trigger((int) $declaration_id, $order, $context); } } catch (Throwable $e) { } }); } public static function append_to_dispatch_email($body, $order = null) { if (!AIEO_Withdrawal::is_enabled()) { return $body; } if (!$order instanceof WC_Order) { return $body; } return rtrim((string) $body) . "\n\n" . "----\n" . self::notice_intro() . "\n" . self::notice_label() . ': ' . self::notice_url($order) . "\n"; } private static function notice_intro() { $settings = AIEO_Withdrawal::settings(); $intro = trim((string) $settings['email_intro']); return $intro !== '' ? $intro : __('You may withdraw from this order within 14 days of receiving it, without giving a reason.', 'ai-eshop-optimizer'); } private static function notice_label() { return __('Press here to withdraw', 'ai-eshop-optimizer'); } private static function notice_url($order) { return class_exists('AIEO_Withdrawal_Guest') ? AIEO_Withdrawal_Guest::form_url_for_order($order) : home_url('/'); } private static function row($label, $value) { return '' . esc_html($intro) . '
'; echo ''; echo '