<?php
/**
 * Warranty Order Completed Email Template (Plain Text)
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/warranty-order-completed.php
 *
 * @package WarrantyCart
 * @var WC_Order        $order              The order object.
 * @var string          $email_heading      The email heading.
 * @var string          $additional_content Additional content.
 * @var bool            $sent_to_admin      Whether sent to admin.
 * @var bool            $plain_text         Whether plain text.
 * @var OrderCompletion $email              The email object.
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound,WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Email template variables and WooCommerce hooks are local scope and don't need prefixing

use WarrantyCart\Notifications\Emails\OrderCompletion;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

echo '= ' . esc_html( $email_heading ) . " =\n\n";

/* translators: %s: Customer first name */
printf( esc_html( __( 'Dear %s,', 'warranty-cart' ) ), esc_html( $order->get_billing_first_name() ) ) . "\n\n";

echo esc_html( __( 'Thank you for your warranty purchase! Your order has been completed successfully.', 'warranty-cart' ) ) . "\n\n";

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

echo esc_html( __( 'Order Details', 'warranty-cart' ) ) . "\n\n";

foreach ( $order->get_items() as $item_id => $item ) :
	$product = $item->get_product();

	echo wp_kses_post( $item->get_name() );

	if ( $product && $product->get_sku() ) {
		echo ' (#' . esc_html( $product->get_sku() ) . ')';
	}

	echo ' x ' . esc_html( $item->get_quantity() ) . ' - ' . wp_kses_post( $order->get_formatted_line_subtotal( $item ) ) . "\n";

	// Allow other plugins to add additional product information here.
	do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
	wc_display_item_meta( $item );
	do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );

	echo "\n";
endforeach;

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

$item_totals = $order->get_order_item_totals();
if ( $item_totals ) {
	foreach ( $item_totals as $total ) {
		echo wp_kses_post( $total['label'] ) . ': ' . wp_kses_post( $total['value'] ) . "\n";
	}
}

echo "\n" . esc_html( __( 'Your warranty certificate has been attached to this email. Please keep it safe for your records.', 'warranty-cart' ) ) . "\n\n";

echo esc_html( __( 'If you have any questions about your warranty, please don\'t hesitate to contact us.', 'warranty-cart' ) ) . "\n\n";

if ( $additional_content ) {
	echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) ) . "\n\n";
}

echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

echo esc_html( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) );
// phpcs:enable
