'' ] );
$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() {
?>