| @@ -38,8 +38,10 @@ | ||
| 38 | 38 | 'plugin_id' => 'woocommerce', |
| 39 | 39 | 'plugin_name' => 'WooCommerce', |
| 40 | 40 | ]; |
| 41 | 41 | |
| 42 | + protected $elements = []; | |
| 43 | + | |
| 42 | 44 | protected $shortcodes = []; |
| 43 | 45 | |
| 44 | 46 | protected $root_email = null; |
| 45 | 47 | |
| @@ -82,9 +84,9 @@ | ||
| 82 | 84 | /** |
| 83 | 85 | * Function check current template is WooCommerce email |
| 84 | 86 | * Return boolean |
| 85 | 87 | */ |
| 86 | - protected function is_template_email( $email ) { | |
| 88 | + protected function is_template_email( \WC_Email $email ) { | |
| 87 | 89 | return ! empty( $email->id ) && $email->id === $this->id; |
| 88 | 90 | } |
| 89 | 91 | |
| 90 | 92 | public function get_language( $order ) { |
| @@ -106,35 +108,15 @@ | ||
| 106 | 108 | if ( ! file_exists( $template_path ) ) { |
| 107 | 109 | return $located; |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | - return $this->load_template( $args ) ? $template_path : $located; | |
| 111 | - } | |
| 112 | + $this->template = new YayMailTemplate( $this->id ); | |
| 112 | 113 | |
| 113 | - /** | |
| 114 | - * Resolve the variant and load the YayMail template into $this->template. | |
| 115 | - * The default design decides whether YayMail renders this email at all; | |
| 116 | - * a variant only swaps the design when an addon returns one via `yaymail_email_get_variant`. | |
| 117 | - * | |
| 118 | - * @param array $args wc_get_template args. | |
| 119 | - * @param string|null $template_name Template to load; defaults to this email's id. | |
| 120 | - * @return bool True when a YayMail template should render. | |
| 121 | - */ | |
| 122 | - protected function load_template( $args, $template_name = null ) { | |
| 123 | - $template_name = $template_name ?? $this->id; | |
| 124 | - $order = isset( $args['order'] ) ? $args['order'] : null; | |
| 125 | - | |
| 126 | - $this->template = new YayMailTemplate( $template_name ); | |
| 127 | 114 | if ( ! $this->template->is_enabled() ) { |
| 128 | - return false; | |
| 115 | + return $located; | |
| 129 | 116 | } |
| 130 | 117 | |
| 131 | - $variant = yaymail_sanitize_template_variant( apply_filters( 'yaymail_email_get_variant', '', $order, $args, $this, $template_name ) ); | |
| 132 | - if ( '' !== $variant ) { | |
| 133 | - $this->template = new YayMailTemplate( $template_name, '', $variant ); | |
| 134 | - } | |
| 135 | - | |
| 136 | - return true; | |
| 118 | + return $template_path; | |
| 137 | 119 | } |
| 138 | 120 | |
| 139 | 121 | public function get_title() { |
| 140 | 122 | return $this->title ?? ''; |
| @@ -147,8 +129,19 @@ | ||
| 147 | 129 | public function get_source() { |
| 148 | 130 | return $this->source; |
| 149 | 131 | } |
| 150 | 132 | |
| 133 | + public function register_element( $element ) { | |
| 134 | + if ( ! ( $element instanceof BaseElement ) ) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + $this->elements[] = $element; | |
| 138 | + } | |
| 139 | + | |
| 140 | + public function get_elements() { | |
| 141 | + return $this->elements; | |
| 142 | + } | |
| 143 | + | |
| 151 | 144 | public function register_shortcodes( $shortcodes ) { |
| 152 | 145 | $this->shortcodes = array_merge( $this->shortcodes, $shortcodes ); |
| 153 | 146 | } |
| 154 | 147 | |
| @@ -170,10 +163,10 @@ | ||
| 170 | 163 | } |
| 171 | 164 | if ( ! $this->root_email || ! $this->root_email instanceof \WC_Email ) { |
| 172 | 165 | return; |
| 173 | 166 | } |
| 174 | - // One batched lookup shared by all emails instead of a per-email query at init. | |
| 175 | - if ( in_array( $this->id, TemplateModel::get_active_default_template_names(), true ) ) { | |
| 167 | + $find_yaymail_template = TemplateModel::get_short_data_by_name( $this->id ); | |
| 168 | + if ( ! empty( $find_yaymail_template ) && $find_yaymail_template['status'] === 'active' ) { | |
| 176 | 169 | $this->root_email->block_email_editor_enabled = false; |
| 177 | 170 | } |
| 178 | 171 | } |
| 179 | 172 | } |