helper = $helper; } public function render($element, $columnBaseWidth) { $couponCode = self::CODE_PLACEHOLDER; if (!empty($element['couponId'])) { try { $couponCode = $this->helper->wcGetCouponCodeById((int)$element['couponId']); } catch (\Exception $e) { if (!$this->helper->isWooCommerceActive()) { throw NewsletterProcessingException::create()->withMessage(__('WooCommerce is not active', 'mailpoet')); } else { throw NewsletterProcessingException::create()->withMessage($e->getMessage())->withCode($e->getCode()); } } if (empty($couponCode)) { throw NewsletterProcessingException::create()->withMessage(__('Couldn\'t find the coupon. Please update the email if the coupon was removed.', 'mailpoet')); } } $element['styles']['block']['width'] = $this->calculateWidth($element, $columnBaseWidth); $styles = 'display:inline-block;-webkit-text-size-adjust:none;mso-hide:all;text-decoration:none;text-align:center;' . StylesHelper::getBlockStyles($element, $exclude = ['textAlign']); $styles = EHelper::escapeHtmlStyleAttr($styles); $template = '
' . EHelper::escapeHtmlText($couponCode) . '
'; return $template; } public function calculateWidth($element, $columnBaseWidth): string { $columnWidth = $columnBaseWidth - (StylesHelper::$paddingWidth * 2); $borderWidth = (int)$element['styles']['block']['borderWidth']; $width = (int)$element['styles']['block']['width']; $width = ($width > $columnWidth) ? $columnWidth : $width; return ($width - (2 * $borderWidth) . 'px'); } }