| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Utils; |
| 4 |
|
| 5 |
use YayMail\Models\TemplateModel; |
| 6 |
use YayMail\Shortcodes\ShortcodesExecutor; |
| 7 |
use YayMail\Models\SettingModel; |
| 8 |
use YayMail\YayMailTemplate; |
| 9 |
|
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* TemplateRenderer Classes |
| 15 |
* Define all utility functions to be used for rendering templates |
| 16 |
*/ |
| 17 |
class TemplateRenderer { |
| 18 |
|
| 19 |
public $template = null; |
| 20 |
|
| 21 |
public function __construct( $template ) { |
| 22 |
if ( $template instanceof YayMailTemplate ) { |
| 23 |
$this->template = $template; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function generate_content( $render_data ) { |
| 28 |
if ( empty( $this->template ) ) { |
| 29 |
return ''; |
| 30 |
} |
| 31 |
|
| 32 |
// Handle the cases when order is numeric (order_id) |
| 33 |
if ( isset( $render_data['order'] ) && is_numeric( $render_data['order'] ) ) { |
| 34 |
$order = wc_get_order( $render_data['order'] ); |
| 35 |
if ( $order ) { |
| 36 |
$render_data['order'] = $order; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
// TODO: Need to generate render_data based on email type |
| 41 |
$args = [ |
| 42 |
'template' => $this->template, |
| 43 |
'render_data' => $render_data, |
| 44 |
'settings' => yaymail_settings(), |
| 45 |
]; |
| 46 |
|
| 47 |
return yaymail_get_content( 'templates/emails/email-content.php', $args ); |
| 48 |
} |
| 49 |
} |
| 50 |
|