| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Emails; |
| 4 |
|
| 5 |
use YayMail\Abstracts\BaseEmail; |
| 6 |
use YayMail\Elements\ElementsLoader; |
| 7 |
use YayMail\Utils\SingletonTrait; |
| 8 |
|
| 9 |
/** |
| 10 |
* FailedOrder Class |
| 11 |
* |
| 12 |
* @method static FailedOrder get_instance() |
| 13 |
*/ |
| 14 |
class FailedOrder extends BaseEmail { |
| 15 |
use SingletonTrait; |
| 16 |
|
| 17 |
protected function __construct() { |
| 18 |
$emails = \WC_Emails::instance()->get_emails(); |
| 19 |
$email = $emails['WC_Email_Failed_Order']; |
| 20 |
if ( ! $email ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
$this->id = $email->id; |
| 25 |
$this->title = $email->get_title(); |
| 26 |
$this->root_email = $email; |
| 27 |
$this->recipient = function_exists( 'yaymail_get_email_recipient_zone' ) ? yaymail_get_email_recipient_zone( $email ) : ''; |
| 28 |
|
| 29 |
$this->render_priority = apply_filters( 'yaymail_email_render_priority', $this->render_priority, $this->id ); |
| 30 |
add_filter( 'wc_get_template', [ $this, 'get_template_file' ], $this->render_priority ?? 10, 3 ); |
| 31 |
$this->maybe_disable_block_email_editor(); |
| 32 |
} |
| 33 |
|
| 34 |
public function get_default_elements() { |
| 35 |
$email_title = __( 'Order Failed: #{order_number}', 'woocommerce' ); |
| 36 |
$email_title = str_replace( '#{order_number}', '#[yaymail_order_number is_plain="true"]', $email_title ); |
| 37 |
// translators: order_id and customer name. |
| 38 |
$email_text = sprintf( esc_html__( 'Payment for order #%1$s from %2$s has failed. The order was as follows:', 'woocommerce' ), '[yaymail_order_number is_plain="true"]', '[yaymail_billing_first_name] [yaymail_billing_last_name]' ); |
| 39 |
$additional_text = __( 'Hopefully they\'ll be back. Read more about <a href=\"https://docs.woocommerce.com/document/managing-orders/\">troubleshooting failed payments</a>.', 'woocommerce' ); |
| 40 |
$additional_text = str_replace( '<a', '<a style=\"color: ' . esc_attr( YAYMAIL_COLOR_WC_DEFAULT ) . ';\"', $additional_text ); |
| 41 |
|
| 42 |
$default_elements = ElementsLoader::load_elements( |
| 43 |
[ |
| 44 |
[ |
| 45 |
'type' => 'Logo', |
| 46 |
], |
| 47 |
[ |
| 48 |
'type' => 'Heading', |
| 49 |
'attributes' => [ |
| 50 |
'rich_text' => $email_title, |
| 51 |
], |
| 52 |
], |
| 53 |
[ |
| 54 |
'type' => 'Text', |
| 55 |
'attributes' => [ |
| 56 |
'rich_text' => '<p><span>' . $email_text . '</span></p>', |
| 57 |
], |
| 58 |
], |
| 59 |
[ |
| 60 |
'type' => 'OrderDetails', |
| 61 |
], |
| 62 |
[ |
| 63 |
'type' => 'BillingShippingAddress', |
| 64 |
], |
| 65 |
[ |
| 66 |
'type' => 'Text', |
| 67 |
'attributes' => [ |
| 68 |
'rich_text' => '<p><span>' . $additional_text . '</span></p>', |
| 69 |
'padding' => [ |
| 70 |
'top' => '0', |
| 71 |
'right' => '50', |
| 72 |
'bottom' => '38', |
| 73 |
'left' => '50', |
| 74 |
], |
| 75 |
], |
| 76 |
], |
| 77 |
[ |
| 78 |
'type' => 'Footer', |
| 79 |
], |
| 80 |
] |
| 81 |
); |
| 82 |
return $default_elements; |
| 83 |
} |
| 84 |
|
| 85 |
public function get_template_path() { |
| 86 |
return yaymail_get_template( 'emails/admin-failed-order.php', '', YAYMAIL_PLUGIN_PATH . 'templates/' ); |
| 87 |
} |
| 88 |
} |
| 89 |
|