'' ] ); $this->template_id = $data['template_id']; add_action( 'viwec_render_content', [ $this, 'render_content' ], 10, 2 ); add_filter( 'gettext', [ $this, 'recover_text' ], 10, 3 ); add_action( 'viwec_order_item_parts', [ $this, 'order_download' ], 10, 3 ); add_filter( 'woocommerce_order_shipping_to_display_shipped_via', [ $this, 'remove_shipping_method' ] ); add_filter( 'woocommerce_email_styles', array( $this, 'custom_style' ), 9999 ); } public static function init( $data = [] ) { if ( null == self::$instance ) { self::$instance = new self( $data ); } return self::$instance; } public function recover_text( $translation, $text, $domain ) { if ( in_array( $text, [ 'Order fully refunded.', 'Refund' ] ) ) { $translation = $text; } return $translation; } public function set_object( $email ) { $this->email_id = $email->id; $object = $email->object; if ( is_a( $object, 'WC_Order' ) ) { $this->order = $object; $this->order_currency = $this->order->get_currency(); } elseif ( is_a( $object, 'WP_User' ) ) { $this->user = $email; } } public function set_user( $user ) { $this->user = $user; } public function order( $order_id ) { if ( $order_id ) { $this->order = wc_get_order( $order_id ); if ( $this->order ) { $this->order_currency = $this->order->get_currency(); } } } public function demo_order() { $this->demo = true; $order = new \WC_Order(); $order->set_id( 123456 ); $order->set_date_created( time() ); $order->set_billing_first_name( 'John' ); $order->set_billing_last_name( 'Doe' ); $order->set_billing_email( 'johndoe@domain.com' ); $order->set_billing_country( 'US' ); $order->set_billing_city( 'Azusa' ); $order->set_billing_state( 'NY' ); $order->set_payment_method( 'paypal' ); $order->set_payment_method_title( 'Paypal' ); $order->set_billing_postcode( 10001 ); $order->set_billing_phone( '0123456789' ); $order->set_billing_address_1( 'Ap #867-859 Sit Rd.' ); $order->set_shipping_total( 10 ); $order->set_total( 60 ); $this->order = $order; } public function demo_new_user() { $user = new \WP_User(); $user->user_login = 'johndoe'; $user->user_pass = '$P$BKpFUPNogZw6kAv/dMrk6CjSmlFI8l0'; $this->user = $user; } public function parse_styles( $data ) { if ( empty( $data ) || ! is_array( $data ) ) { return $data; } $style = ''; $ignore_arr = [ 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width', 'border-style', 'border-color', 'border-top-color', 'border-width', ]; foreach ( $data as $key => $value ) { if ( in_array( $key, $ignore_arr ) ) { continue; } $style .= "{$key}:{$value};"; } $border_style = $data['border-style'] ?? 'solid'; $border_color = $data['border-color'] ?? ( $data['border-top-color'] ?? 'transparent' ); if ( isset( $data['border-top-width'] ) ) { foreach ( [ 'top', 'right', 'bottom', 'left' ] as $pos ) { $style .= ! isset( $data["border-{$pos}-width"] ) || $data["border-{$pos}-width"] === '0px' ? "border-{$pos}:0 hidden;" : "border-{$pos}:{$data["border-{$pos}-width"]} {$border_style} {$border_color};"; } } elseif ( isset( $data['border-width'] ) ) { $border_width = $data['border-width']; if ( $border_width !== '0px' ) { $style .= " border-width: {$border_width}; "; $style .= " border-style: {$border_style}; "; $style .= " border-color: {$border_color}; "; } else { $style .= " border:0 hidden; "; } } return esc_attr( $style ); } public function replace_template( $located, $template_name ) { if ( $template_name == 'emails/email-styles.php' ) { $located = VIWEC_TEMPLATES . 'email-style.php'; } return $located; } public function render( $data ) { $this->check_rendered = true; $bg_style = ''; $width = 600; $responsive = 414; if ( isset( $data['style_container'] ) ) { $width = ! empty( $data['style_container']['width'] ) ? $data['style_container']['width'] : $width; $responsive = ! empty( $data['style_container']['responsive'] ) ? $data['style_container']['responsive'] : $responsive; unset( $data['style_container']['width'] ); unset( $data['style_container']['responsive'] ); $bg_style = isset( $data['style_container'] ) ? $this->parse_styles( $data['style_container'] ) : ''; } $this->direction = get_post_meta( $this->template_id, 'viwec_settings_direction', true ); if ( $this->preview ) { $this->direction = isset( $_POST['direction'] ) ? sanitize_text_field( wp_unslash( $_POST['direction'] ) ) : 'ltr';// phpcs:ignore WordPress.Security.NonceVerification.Missing } $this->email_header( $bg_style, $width, $responsive ); $left_align = $this->direction == 'rtl' ? 'right' : 'left'; $custom_css_component = get_post_meta( $this->template_id, 'viwec_custom_css', true ); ?> parse_styles( $row['props']['style_outer'] ) : ''; ?>
$col ) { $col_style = ! empty( $col['props']['style'] ) ? $this->parse_styles( $col['props']['style'] ) : ''; if ( $start == $key ) { ?>
use_default_template && ! $this->recover_heading && ! $this->class_email ) { continue; } $content_style = isset( $el['style'] ) ? $this->parse_styles( str_replace( "'", '', $el['style'] ) ) : ''; $el_style = ! empty( $el['props']['style'] ) ? $this->parse_styles( str_replace( "'", '', $el['props']['style'] ) ) : ''; ?>
props = $el; do_action( 'viwec_render_content', $type, $el, $this ); ?>
email_footer(); } public function email_header( $bg_style, $width, $responsive ) { wc_get_template( 'email-header.php', [ 'bg_style' => $bg_style, 'width' => $width, 'responsive' => $responsive, 'direction' => $this->direction ], '', VIWEC_TEMPLATES ); } public function email_footer() { ?> $func( $props ); } } public function custom_style() { return $this->custom_css ? $this->custom_css : ''; } public function replace_shortcode( $text ) { $object = ''; if ( $this->order ) { $object = $this->order; } elseif ( $this->user ) { $object = $this->user; } $text = Utils::replace_shortcode( $text, $this->template_args, $object, $this->preview ); return $text; } public function render_html_image( $props ) { $src = isset( $props['attrs']['src'] ) ? $props['attrs']['src'] : ''; $width = isset( $props['childStyle']['img'] ) ? $this->parse_styles( $props['childStyle']['img'] ) : ''; $ol_width = ! empty( $props['childStyle']['img']['width'] ) ? str_replace( 'px', '', $props['childStyle']['img']['width'] ) : '100%'; $href = ! empty( $props['attrs']['data-href'] ) ? $props['attrs']['data-href'] : ''; $alt = ! empty( $props['attrs']['data-alt'] ) ? $props['attrs']['data-alt'] : ''; if ( ! empty( $href ) ) { ?> <?php echo esc_attr( $alt ); ?> replace_shortcode( $content ); echo wp_kses( do_shortcode( $content ), viwec_allowed_html() ); } public function render_html_order_detail( $props ) { if ( $this->order ) { $temp = ! empty( $props['attrs']['data-template'] ) ? $props['attrs']['data-template'] : 1; $preview = $this->demo ? 'pre-' : ''; if ( $preview ) { $this->direction = isset( $_POST['direction'] ) ? sanitize_text_field( wp_unslash( $_POST['direction'] ) ) : 'ltr';// phpcs:ignore WordPress.Security.NonceVerification.Missing } if ( is_file( VIWEC_TEMPLATES . "order-items/{$preview}style-{$temp}.php" ) ) { ?>
template_args['sent_to_admin'] ?? ''; wc_get_template( "order-items/{$preview}style-{$temp}.php", [ 'order' => $this->order, 'items' => $this->order->get_items(), 'show_sku' => $sent_to_admin, 'show_download_links' => $this->order->is_download_permitted() && ! $sent_to_admin, 'show_purchase_note' => $this->order->is_paid() && ! $sent_to_admin, 'props' => $props, 'render' => $this, 'direction' => $this->direction ], 'email-template-customizer', VIWEC_TEMPLATES ); ?>
order ) { $left_style = isset( $props['childStyle']['.viwec-td-left'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-left'] ) : 'text-align:left;'; $right_style = isset( $props['childStyle']['.viwec-td-right'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-right'] ) : 'text-align:right; width:40%;'; $el_style = isset( $props['childStyle']['.viwec-order-subtotal-style'] ) ? $this->parse_styles( $props['childStyle']['.viwec-order-subtotal-style'] ) : ''; $p_style = $this->get_p_inherit_style( $props ); $item_totals = $this->order->get_order_item_totals(); if ( ! empty( $item_totals ) && is_array( $item_totals ) ) { foreach ( $item_totals as $id => $item ) { switch ( $id ) { case 'cart_subtotal': $id = 'subtotal'; break; default: break; } $label = str_replace( ':', '', $item['label'] ); if ( $label == 'Order fully refunded.' && ! empty( $props['content']['refund-full'] ) ) { $label = $props['content']['refund-full']; } if ( $label == 'Refund' && ! empty( $props['content']['refund-part'] ) ) { $label = $props['content']['refund-part']; } if ( in_array( $id, [ 'order_total', 'payment_method' ] ) ) { continue; } $text = $props['content'][ $id ] ?? $label; $html .= ""; $html .= "

{$text}

"; $html .= "

{$item['value']}

"; $html .= ""; } } } $this->table( $html ); } public function render_html_order_total( $props ) { $html = ''; if ( $this->order ) { $left_style = isset( $props['childStyle']['.viwec-td-left'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-left'] ) : 'text-align:left;'; $right_style = isset( $props['childStyle']['.viwec-td-right'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-right'] ) : 'text-align:right; width:40%;'; $el_style = isset( $props['childStyle']['.viwec-order-total-style'] ) ? $this->parse_styles( $props['childStyle']['.viwec-order-total-style'] ) : ''; $trans_total = $props['content']['order_total'] ?? esc_html__( 'Total', 'viwec-email-template-customizer' ); $p_style = $this->get_p_inherit_style( $props ); $tax_display = get_option( 'woocommerce_tax_display_cart' ); $total_html = "

{$trans_total}

"; $total_html .= "

{$this->order->get_formatted_order_total($tax_display)}

"; $html .= $total_html; } $this->table( $html ); } public function render_html_order_note( $props ) { if ( $this->order && $this->order->get_customer_note() ) { $html = ''; $left_style = isset( $props['childStyle']['.viwec-td-left'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-left'] ) : 'text-align:left;'; $right_style = isset( $props['childStyle']['.viwec-td-right'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-right'] ) : 'text-align:right; width:40%;'; $el_style = isset( $props['childStyle']['.viwec-order-total-style'] ) ? $this->parse_styles( $props['childStyle']['.viwec-order-total-style'] ) : ''; $p_style = $this->get_p_inherit_style( $props ); $trans_note = $props['content']['order_note'] ?? 'Note'; $note_html = "

{$trans_note}

"; $note_html .= "

{$this->order->get_customer_note()}

"; $html .= $note_html; $this->table( $html ); } } public function render_html_shipping_method( $props ) { if ( $this->order ) { if ( $shipping_method = $this->order->get_shipping_method() ?? '' ) { $shipping_method_html = ''; $left_style = isset( $props['childStyle']['.viwec-td-left'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-left'] ) : 'text-align:left;'; $right_style = isset( $props['childStyle']['.viwec-td-right'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-right'] ) : 'text-align:right; width:40%;'; $el_style = isset( $props['childStyle']['.viwec-shipping-method-style'] ) ? $this->parse_styles( $props['childStyle']['.viwec-shipping-method-style'] ) : ''; $p_style = $this->get_p_inherit_style( $props ); $trans_shipping_method = $props['content']['shipping_method'] ?? esc_html__( 'Shipping method', 'viwec-email-template-customizer' ); $shipping_method_html .= "

{$trans_shipping_method}

"; $shipping_method_html .= "

{$shipping_method}

"; $this->table( $shipping_method_html ); } } } public function render_html_payment_method( $props ) { $html = ''; if ( $this->order ) { $payment_method_html = ''; $left_style = isset( $props['childStyle']['.viwec-td-left'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-left'] ) : 'text-align:left;'; $right_style = isset( $props['childStyle']['.viwec-td-right'] ) ? $this->parse_styles( $props['childStyle']['.viwec-td-right'] ) : 'text-align:right; width:40%;'; $el_style = isset( $props['childStyle']['.viwec-payment-method-style'] ) ? $this->parse_styles( $props['childStyle']['.viwec-payment-method-style'] ) : ''; $payment_method = $this->order->get_total() > 0 && $this->order->get_payment_method_title() && 'other' !== $this->order->get_payment_method_title() ? $this->order->get_payment_method_title() : ''; $p_style = $this->get_p_inherit_style( $props ); $trans_payment_method = $props['content']['payment_method'] ?? esc_html__( 'Payment method', 'viwec-email-template-customizer' ); if ( $payment_method ) { $payment_method_html = "

{$trans_payment_method}

"; $payment_method_html .= "

{$payment_method}

"; } $html .= $payment_method_html; } $this->table( $html ); } public function render_html_billing_address( $props ) { if ( ! $this->order ) { return; } if ( $this->preview ) { $this->render_html_billing_address_via_hook( '', '', '', '', $props ); } else { add_action( 'woocommerce_email_customer_details', [ $this, 'render_html_billing_address_via_hook' ], 20, 5 ); $args = $this->template_args; do_action( 'woocommerce_email_customer_details', $args['order'], $args['sent_to_admin'], $args['plain_text'], $args['email'], $props ); remove_action( 'woocommerce_email_customer_details', [ $this, 'render_html_billing_address_via_hook' ], 20 ); } } public function render_html_billing_address_via_hook( $order, $sent_to_admin, $plain_text, $email, $props ) { if ( $props['type'] !== 'html/billing_address' ) { return; } $color = $props['style']['color'] ?? 'inherit'; $font_weight = $props['style']['font-weight'] ?? 'inherit'; $billing_address = $this->order->get_formatted_billing_address(); $billing_address = str_replace( '
', "", $billing_address ); $billing_email = $billing_phone = ''; if ( $phone = $this->order->get_billing_phone() ) { $billing_phone = "$phone"; } if ( $this->order->get_billing_email() ) { $billing_email = "{$this->order->get_billing_email()}"; } $html = "{$billing_address}{$billing_phone}{$billing_email}"; $this->table( $html ); } public function render_html_shipping_address( $props ) { if ( ! $this->order ) { return; } if ( $this->preview ) { $this->render_html_shipping_address_via_hook( '', '', '', '', $props ); } else { add_action( 'woocommerce_email_customer_details', [ $this, 'render_html_shipping_address_via_hook' ], 20, 5 ); $args = $this->template_args; do_action( 'woocommerce_email_customer_details', $args['order'], $args['sent_to_admin'], $args['plain_text'], $args['email'], $props ); remove_action( 'woocommerce_email_customer_details', [ $this, 'render_html_shipping_address_via_hook' ], 20 ); } } public function render_html_shipping_address_via_hook( $order, $sent_to_admin, $plain_text, $email, $props ) { if ( $props['type'] !== 'html/shipping_address' ) { return; } $color = $props['style']['color'] ?? 'inherit'; $font_weight = $props['style']['font-weight'] ?? 'inherit'; $shipping_address = $this->order->get_formatted_shipping_address(); $shipping_address = empty( $shipping_address ) ? $this->order->get_formatted_billing_address() : $shipping_address; $shipping_address = str_replace( '
', "", $shipping_address ); $shipping_phone = ''; if ( $phone = $this->order->get_shipping_phone() ) { $shipping_phone = "$phone"; } $html = "{$shipping_address}{$shipping_phone}"; $this->table( $html ); } public function render_html_social( $props ) { $align = $props['style']['text-align'] ?? 'left'; $socials = [ 'facebook', 'twitter', 'instagram', 'youtube', 'linkedin', 'whatsapp', 'telegram', 'tiktok' ]; $html = ''; $width = ! empty( $props['attrs']['data-width'] ) ? $props['attrs']['data-width'] : 32; if ( isset( $props['attrs']['direction'] ) && $props['attrs']['direction'] === 'vertical' ) { foreach ( $socials as $social ) { $link = isset( $props['attrs'][ $social . '_url' ] ) ? esc_url( $props['attrs'][ $social . '_url' ] ) : ''; $img = isset( $props['attrs'][ $social ] ) ? esc_url( $props['attrs'][ $social ] ) : ''; if ( ! empty( $img ) && ! empty( $link ) ) { $html .= ""; } } } else { $html = ''; foreach ( $socials as $social ) { $link = isset( $props['attrs'][ $social . '_url' ] ) ? esc_url( $props['attrs'][ $social . '_url' ] ) : ''; $img = isset( $props['attrs'][ $social ] ) ? esc_url( $props['attrs'][ $social ] ) : ''; if ( ! empty( $img ) && ! empty( $link ) ) { $html .= ""; } } $html .= ''; } $html = "$html
"; echo wp_kses( $html, viwec_allowed_html() ); } public function render_html_button( $props ) { $url = isset( $props['attrs']['href'] ) ? $this->replace_shortcode( $props['attrs']['href'] ) : ''; $text = isset( $props['content']['text'] ) ? $this->replace_shortcode( $props['content']['text'] ) : ''; $text = str_replace( [ '

', '

' ], [ '', '' ], $text ); $align = $props['style']['text-align'] ?? 'left'; $style = isset( $props['childStyle']['a'] ) ? $props['childStyle']['a'] : []; $padding = ! empty( $style['padding'] ) ? $style['padding'] : ''; $border_radius = ! empty( $style['border-radius'] ) ? $style['border-radius'] : ''; $bg_color = ! empty( $style['background-color'] ) ? $style['background-color'] : 'inherit'; unset( $style['padding'] ); $style = $this->parse_styles( $style ); $text_color = $props['style']['color'] ?? 'inherit'; $font_weight = $props['style']['font-weight'] ?? 'normal'; $width = $props['childStyle']['a']['width'] ?? ''; $line_height = $props['style']['line-height'] ?? 1; $height = str_replace( 'px', '', $line_height ); $a_style = [ "color:{$text_color} !important", "font-weight:{$font_weight}", "display:block;text-decoration:none;text-transform:none;margin:0;text-align: center;max-width: 100%", "background-color:{$bg_color}", "line-height:{$line_height}", "height:{$line_height}", ]; ?> $value ) { $link = isset( $props['attrs'][ $key ] ) ? $this->replace_shortcode( $props['attrs'][ $key ] ) : ''; if ( empty( $value ) || ! $link ) { continue; } ?> $value ) { $link = isset( $props['attrs'][ $key ] ) ? $this->replace_shortcode( $props['attrs'][ $key ] ) : ''; if ( empty( $value ) || ! $link ) { continue; } ?>
parse_styles( $props['childStyle']['hr'] ) : ''; ?>
parse_styles( $props['childStyle']['.viwec-spacer'] ) : ''; $mobile_hidden = ! empty( $props['attrs']['mobile-hidden'] ) && $props['attrs']['mobile-hidden'] == 'true' ? 'viwec-mobile-hidden' : ''; ?>
replace_shortcode( $props['attrs']['home_link'] ) : ''; $text = isset( $props['content']['home_text'] ) ? $this->replace_shortcode( $props['content']['home_text'] ) : ''; ?> replace_shortcode( $props['attrs']['email_link'] ); ?>
' style='padding-right: 3px;'>
' style='padding-right: 3px;'>
' style='padding-right: 3px;'> '>
parse_styles( $props['childStyle']['h2'] ) . 'margin:0;' : ''; $class_td = ! empty( $props['childStyle']['.td'] ) ? $this->parse_styles( $props['childStyle']['.td'] ) : ''; $table_head = ! empty( $props['childStyle']['.head.td'] ) ? $this->parse_styles( $props['childStyle']['.head.td'] ) : ''; $table_body = ! empty( $props['childStyle']['.body.td'] ) ? $this->parse_styles( $props['childStyle']['.body.td'] ) : ''; $this->custom_css .= $h2 ? ".{$hook} h1,.{$hook} h2,.{$hook} h3,.{$hook} h4,.{$hook} h5,.{$hook} h6{{$h2}}" : ''; $this->custom_css .= $h2 ? ".{$hook} h1 a,.{$hook} h2 a,.{$hook} h3 a,.{$hook} h4 a,.{$hook} h5 a,.{$hook} h6 a {{$h2}}" : ''; $this->custom_css .= $class_td ? ".{$hook} th.td,.{$hook} td.td{padding:8px;{$class_td}}" : ''; $this->custom_css .= $table_body ? ".{$hook} tbody .td{{$table_body}}" : ''; $this->custom_css .= $table_body ? ".{$hook} tfoot .td {{$table_body}}" : ''; $this->custom_css .= $table_head ? ".{$hook} thead .td{{$table_head}}" : ''; $this->custom_css .= $this->custom_css ? ".{$hook} table{border-collapse:collapse; border:none !important;} blockquote{margin:5px 20px;} .{$hook} img{padding-right:8px;} ul, li{margin:0;} div{margin-bottom:0 !important;}" : ''; if ( $this->preview ) { wc()->mailer(); $class_email = new \WC_Email(); ob_start(); switch ( $hook ) { case '': case 'woocommerce_email_before_order_table': do_action( 'woocommerce_email_before_order_table', $this->order, false, false, '' ); break; case 'woocommerce_email_after_order_table': do_action( 'woocommerce_email_after_order_table', $this->order, false, false, '' ); break; case 'woocommerce_email_order_meta': do_action( 'woocommerce_email_order_meta', $this->order, false, false, '' ); break; } $content = ob_get_clean(); if ( ! $content ) { ob_start(); ?>

ID Items
1 Item
2 Item
style_inline( "
" . $content . '
' ); echo wp_kses_post( str_replace( [ 'margin-bottom: 40px;' ], [ '' ], $content ) ); } else { $args = $this->template_args; printf( "
", esc_attr( $hook ) ); switch ( $hook ) { case '': case 'woocommerce_email_before_order_table': do_action( 'woocommerce_email_before_order_table', $args['order'], $args['sent_to_admin'], $args['plain_text'], $args['email'] ); break; case 'woocommerce_email_after_order_table': // remove_action( 'woocommerce_email_after_order_table', [ \WC_Subscriptions_Order::class, 'add_sub_info_email' ], 15 ); do_action( 'woocommerce_email_after_order_table', $args['order'], $args['sent_to_admin'], $args['plain_text'], $args['email'] ); break; case 'woocommerce_email_order_meta': do_action( 'woocommerce_email_order_meta', $args['order'], $args['sent_to_admin'], $args['plain_text'], $args['email'] ); break; } echo "
"; } } public function render_html_recover_heading( $props ) { if ( $this->preview ) { echo esc_html__( 'Thank you for your order', 'viwec-email-template-customizer' ); } if ( ! $this->use_default_template ) { return; } if ( $this->class_email ) { echo wp_kses( $this->class_email->get_heading(), viwec_allowed_html() ); } if ( $this->recover_heading ) { echo esc_html( $this->recover_heading ); } } public function render_html_recover_content( $props ) { $link_color = $props['childStyle']['p']['color'] ?? '#444444'; $p = ! empty( $props['childStyle']['p'] ) ? $this->parse_styles( $props['childStyle']['p'] ) : ''; $h2 = ! empty( $props['childStyle']['h2'] ) ? $this->parse_styles( $props['childStyle']['h2'] ) : ''; $h2 = str_replace( 'padding', 'margin', $h2 ); $class_td = ! empty( $props['childStyle']['.td'] ) ? $this->parse_styles( $props['childStyle']['.td'] ) : ''; $table_head = ! empty( $props['childStyle']['.head.td'] ) ? $this->parse_styles( $props['childStyle']['.head.td'] ) : ''; $table_body = ! empty( $props['childStyle']['.body.td'] ) ? $this->parse_styles( $props['childStyle']['.body.td'] ) : ''; $label_items = ! empty( $props['childStyle']['th.body.td'] ) ? $this->parse_styles( $props['childStyle']['th.body.td'] ) : ''; $value_items = ! empty( $props['childStyle']['td.body.td'] ) ? $this->parse_styles( $props['childStyle']['td.body.td'] ) : ''; $this->custom_css .= "#viwec-transferred-content address{padding:0 !important; border:none !important;}"; $this->custom_css .= $p ? "#viwec-transferred-content p, #viwec-transferred-content #addresses td{{$p}}" : ''; $this->custom_css .= $h2 ? "#viwec-transferred-content h1,#viwec-transferred-content h2,#viwec-transferred-content h3, #viwec-transferred-content h4,#viwec-transferred-content h5,#viwec-transferred-content h6{{$h2}}" : ''; $this->custom_css .= $h2 ? "#viwec-transferred-content h1 a,#viwec-transferred-content h2 a,#viwec-transferred-content h3 a, #viwec-transferred-content h4 a,#viwec-transferred-content h5 a,#viwec-transferred-content h6 a {{$h2}}" : ''; $this->custom_css .= $class_td ? "#viwec-transferred-content th.td,#viwec-transferred-content td.td{padding:8px;{$class_td}}" : ''; $this->custom_css .= $table_body ? "#viwec-transferred-content tbody td, #viwec-transferred-content tbody .td{{$table_body}}" : ''; $this->custom_css .= $table_body ? "#viwec-transferred-content tfoot td, #viwec-transferred-content tfoot .td {{$table_body}}" : ''; $this->custom_css .= $table_head ? "#viwec-transferred-content thead td, #viwec-transferred-content thead .td{{$table_head}}" : ''; $this->custom_css .= $label_items ? "#viwec-transferred-content tfoot th, #viwec-transferred-content tfoot th.td{{$label_items}}" : ''; $this->custom_css .= $value_items ? "#viwec-transferred-content tbody td, #viwec-transferred-content tfoot td, #viwec-transferred-content tbody td.td, #viwec-transferred-content tfoot td.td{{$value_items}}" : ''; $this->custom_css .= $this->custom_css ? '#viwec-transferred-content table{ border:none !important;} blockquote{margin:5px 20px;} #viwec-transferred-content img{padding-right:8px;} ul, li{margin:0;} ul.wc-item-meta{padding: 10px 0;}' : ''; $this->custom_css .= "a{color:{$link_color} !important;}"; if ( $this->preview ) { add_filter( 'woocommerce_email_order_items_args', [ $this, 'show_image' ] ); wc()->mailer(); $class_email = new \WC_Email(); ob_start(); printf( "

Hi %s, Just to let you know — we've received your order #%s, and it is now being processed:

", esc_html( $this->order->get_billing_first_name() ), absint( $this->order->get_id() ) ); do_action( 'woocommerce_email_order_details', $this->order, false, false, '' ); do_action( 'woocommerce_email_order_meta', $this->order, false, false, '' ); do_action( 'woocommerce_email_customer_details', $this->order, false, false, '' ); $content = ob_get_clean(); $content = preg_replace( '/border=[\'\"]\d+[\'\"]/', 'border="0"', $content ); $content = '
' . wp_kses_post( $content ) . '
'; $content = $class_email->style_inline( $content ); $content = str_replace( [ 'margin-bottom: 40px;', 'border-top-width: 4px;' ], '', $content ); echo wp_kses_post( $content ); } if ( ! $this->use_default_template ) { return; } if ( $this->other_message_content ) { $content = str_replace( [ 'margin-bottom: 40px;', 'border-top-width: 4px;' ], '', $this->other_message_content ); $content = preg_replace( '/border=[\'"]\d+[\'"]/', 'border="0"', $content ); echo '
' . wp_kses( $content, viwec_allowed_html() ) . '
'; } } /*For 3rd compatible*/ public function render_html_coupon( $props ) { $type = $props['attrs']['data-coupon-type'] ?? ''; $coupon_code = $props['content']['data-coupon-code'] ?? ''; $align = $props['style']['text-align'] ?? 'left'; $text_color = $props['style']['color'] ?? 'inherit'; $font_weight = $props['style']['font-weight'] ?? 'normal'; $width = $props['childStyle']['.viwec-coupon']['width'] ?? ''; $style = isset( $props['childStyle']['.viwec-coupon'] ) ? $this->parse_styles( $props['childStyle']['.viwec-coupon'] ) : ''; if ( $type == 2 ) { $coupon_code = $this->preview ? 's0kvk4kp' : $this->generate_coupon( $props ); } if ( ! $coupon_code || $coupon_code === 'COUPONCODE' ) { return; } $coupon_code = strtoupper( $coupon_code ); $this->render_data['coupon'] = $coupon_code; $coupon_obj = new \WC_Coupon( $coupon_code ); $coupon_ex_date = $coupon_obj->get_date_expires(); if ( $coupon_ex_date ) { $coupon_ex_date = $coupon_ex_date->date_i18n( wc_date_format() ); } $this->template_args['coupon_expire_date'] = $coupon_ex_date; ?> props['attrs']['show_img'] ) && $this->props['attrs']['show_img'] == 'true' ? true : false; $args['image_size'] = ! empty( $this->props['childStyle']['img']['width'] ) ? [ (int) $this->props['childStyle']['img']['width'], 300 ] : [ 32, 32 ]; return $args; } public function table( $content, $style = '', $width = '100%', $attr = [] ) { ?>
= 0 ? $option['data-coupon-amount'] : 0; $type = ! empty( $option['data-discount-type'] ) ? $option['data-discount-type'] : 'percent'; $prefix = ! empty( $option['data-discount-prefix'] ) ? $option['data-discount-prefix'] : ''; if ( ! in_array( $type, array_keys( wc_get_coupon_types() ) ) || ( $type == 'percent' && $amount > 100 ) ) { return ''; } $code = $this->generate_coupon_code( $prefix ); $coupon = new \WC_Coupon( $code ); $coupon->set_discount_type( $type ); $coupon->set_amount( $amount ); if ( ! empty( $option['data-coupon-expiry-date'] ) ) { $coupon->set_date_expires( current_time( 'U' ) + $option['data-coupon-expiry-date'] * DAY_IN_SECONDS ); } if ( ! empty( $option['data-coupon-min-spend'] ) ) { $coupon->set_minimum_amount( $option['data-coupon-min-spend'] ); } if ( ! empty( $option['data-coupon-max-spend'] ) ) { $coupon->set_maximum_amount( $option['data-coupon-max-spend'] ); } if ( ! empty( $option['data-coupon-individual'] ) ) { $coupon->set_individual_use( $option['data-coupon-individual'] ); } if ( ! empty( $option['data-coupon-exclude-sale'] ) ) { $coupon->set_exclude_sale_items( $option['data-coupon-exclude-sale'] ); } if ( ! empty( $option['data-coupon-allow-free-shipping'] ) ) { $coupon->set_free_shipping( $option['data-coupon-allow-free-shipping'] ); } if ( ! empty( $option['data-coupon-include-product'] ) ) { $coupon->set_product_ids( explode( ',', $option['data-coupon-include-product'] ) ); } if ( ! empty( $option['data-coupon-exclude-product'] ) ) { $coupon->set_excluded_product_ids( explode( ',', $option['data-coupon-exclude-product'] ) ); } if ( ! empty( $option['data-coupon-include-categories'] ) ) { $coupon->set_product_categories( explode( ',', $option['data-coupon-include-categories'] ) ); } if ( ! empty( $option['data-coupon-exclude-categories'] ) ) { $coupon->set_excluded_product_categories( explode( ',', $option['data-coupon-exclude-categories'] ) ); } if ( ! empty( $option['data-coupon-limit-quantity'] ) ) { $coupon->set_usage_limit( $option['data-coupon-limit-quantity'] ); } if ( ! empty( $option['data-coupon-limit-items'] ) ) { $coupon->set_limit_usage_to_x_items( $option['data-coupon-limit-items'] ); } if ( ! empty( $option['data-coupon-limit-users'] ) ) { $coupon->set_usage_limit_per_user( $option['data-coupon-limit-users'] ); } $coupon_id = $coupon->save(); if ( $coupon_id && class_exists( 'Dokan_Pro' ) ) { update_post_meta( $coupon_id, 'admin_coupons_enabled_for_vendor', 'yes' ); } return $code; } public function generate_coupon_code( $prefix = '' ) { $code = $prefix; $character_arr = array_merge( range( 'a', 'z' ), range( 0, 9 ) ); for ( $i = 0; $i < 8; $i ++ ) { $rand = wp_rand( 0, count( $character_arr ) - 1 ); $code .= $character_arr[ $rand ]; } $args = array( 'post_type' => 'shop_coupon', 'post_status' => 'publish', 'posts_per_page' => - 1, 'title' => $code ); $the_query = new \WP_Query( $args ); if ( $the_query->have_posts() ) { $code = $this->generate_coupon_code( $prefix ); } wp_reset_postdata(); return $code; } public function order_download( $item_id, $item, $order ) { $show_downloads = $order->has_downloadable_item() && $order->is_download_permitted(); if ( ! $show_downloads ) { return; } $pid = $item->get_data()['product_id']; $downloads = $order->get_downloadable_items(); foreach ( $downloads as $download ) { if ( $pid == $download['product_id'] ) { $href = esc_url( $download['download_url'] ); $display = esc_html( $download['download_name'] ); $expires = ''; if ( ! empty( $download['access_expires'] ) ) { $datetime = esc_attr( date_i18n( 'Y-m-d', strtotime( $download['access_expires'] ) ) ); $title = esc_attr( strtotime( $download['access_expires'] ) ); $display_time = esc_html( date_i18n( get_option( 'date_format' ), strtotime( $download['access_expires'] ) ) ); $expires = "- "; } printf( "

%s %s

", esc_url( $href ), esc_html( $display ), esc_html( $expires ) ); } } } public function remove_shipping_method( $shipping_display ) { if ( $this->order ) { return ''; } return $shipping_display; } public function get_style( $props, $layer1, $layer2 = '' ) { if ( ! $props || ! $layer1 ) { return ''; } if ( $layer2 ) { $data = $props[ $layer1 ][ $layer2 ] ?? ''; } else { $data = $props[ $layer1 ] ?? ''; } return $this->parse_styles( $data ); } }