show_product_item_cost = isset( $yaymail_settings['show_product_item_cost'] ) ? boolval( $yaymail_settings['show_product_item_cost'] ) : false; $this->colspan_value = $is_placeholder ? '{{show_product_item_cost}}' : ( $this->show_product_item_cost ? '3' : '2' ); $this->element_data = $element_data; $this->is_placeholder = $is_placeholder; $this->initialize_titles(); if ( ! Helpers::is_woocommerce_order( $order ) ) { $this->initialize_sample_data(); } else { $this->initialize_order_data( $order ); } } public function initialize_titles() { $this->titles = [ 'product' => isset( $this->element_data['product_title'] ) ? $this->element_data['product_title'] : TemplateHelpers::get_content_as_placeholder( 'product_title', esc_html__( 'Product', 'woocommerce' ), $this->is_placeholder ), 'cost' => isset( $this->element_data['cost_title'] ) ? $this->element_data['cost_title'] : TemplateHelpers::get_content_as_placeholder( 'cost_title', esc_html__( 'Cost', 'woocommerce' ), $this->is_placeholder ), 'quantity' => isset( $this->element_data['quantity_title'] ) ? $this->element_data['quantity_title'] : TemplateHelpers::get_content_as_placeholder( 'quantity_title', esc_html__( 'Quantity', 'woocommerce' ), $this->is_placeholder ), 'price' => isset( $this->element_data['price_title'] ) ? $this->element_data['price_title'] : TemplateHelpers::get_content_as_placeholder( 'price_title', esc_html__( 'Price', 'woocommerce' ), $this->is_placeholder ), 'cart_subtotal' => isset( $this->element_data['cart_subtotal_title'] ) ? $this->element_data['cart_subtotal_title'] : TemplateHelpers::get_content_as_placeholder( 'cart_subtotal_title', esc_html__( 'Subtotal:', 'woocommerce' ), $this->is_placeholder ), 'shipping' => isset( $this->element_data['shipping_title'] ) ? $this->element_data['shipping_title'] : TemplateHelpers::get_content_as_placeholder( 'shipping_title', esc_html__( 'Shipping:', 'woocommerce' ), $this->is_placeholder ), 'discount' => isset( $this->element_data['discount_title'] ) ? $this->element_data['discount_title'] : TemplateHelpers::get_content_as_placeholder( 'discount_title', esc_html__( 'Discount:', 'woocommerce' ), $this->is_placeholder ), 'payment_method' => isset( $this->element_data['payment_method_title'] ) ? $this->element_data['payment_method_title'] : TemplateHelpers::get_content_as_placeholder( 'payment_method_title', esc_html__( 'Payment method:', 'woocommerce' ), $this->is_placeholder ), 'order_total' => isset( $this->element_data['order_total_title'] ) ? $this->element_data['order_total_title'] : TemplateHelpers::get_content_as_placeholder( 'order_total_title', esc_html__( 'Total:', 'woocommerce' ), $this->is_placeholder ), 'order_note' => isset( $this->element_data['order_note_title'] ) ? $this->element_data['order_note_title'] : TemplateHelpers::get_content_as_placeholder( 'order_note_title', esc_html__( 'Note:', 'woocommerce' ), $this->is_placeholder ), ]; } private function initialize_sample_data() { $this->item_totals = [ 'cart_subtotal' => [ 'label' => $this->titles['cart_subtotal'], 'value' => wc_price( 18 ), ], 'shipping' => [ 'label' => $this->titles['shipping'], 'value' => __( 'Free shipping', 'yaymail' ), ], 'payment_method' => [ 'label' => $this->titles['payment_method'], 'value' => __( 'Direct bank transfer', 'yaymail' ), ], 'order_total' => [ 'label' => $this->titles['order_total'], 'value' => wc_price( 18 ), ], ]; $this->order_note = 'YayMail'; } private function initialize_order_data( $order ) { $this->item_totals = $order->get_order_item_totals(); $this->order_note = $order->get_customer_note(); $this->order = $order; } public function get_styles() { return TemplateHelpers::get_style( [ 'padding' => '12px', 'text-align' => yaymail_get_text_align(), 'font-family' => TemplateHelpers::get_font_family_value( isset( $this->element_data['font_family'] ) ? $this->element_data['font_family'] : 'inherit' ), 'color' => isset( $this->element_data['text_color'] ) ? $this->element_data['text_color'] : 'inherit', 'border-width' => '1px', 'border-style' => 'solid', 'border-color' => isset( $this->element_data['border_color'] ) ? $this->element_data['border_color'] : 'inherit', ] ); } public function get_styles_product_image() { $direction = yaymail_get_email_direction(); if ( 'ltr' === $direction ) { $margin_right = '5px'; $margin_left = '0'; } else { $margin_right = '0'; $margin_left = '5px'; } return TemplateHelpers::get_style( [ 'margin-bottom' => '5px', 'margin-right' => $margin_right, 'margin-left' => $margin_left, ] ); } public function get_structure_table() { return apply_filters( 'yaymail_order_details_structure_table', [ 'items' => [ 'product' => [ 'label' => $this->titles['product'], 'col_span' => apply_filters( 'yaymail_order_item_product_title_colspan', 1, $this->element_data ), 'style' => [ 'word-wrap' => 'break-word', 'width' => $this->show_product_item_cost ? '40%' : '45%', ], ], 'cost' => [ 'label' => $this->titles['cost'], 'col_span' => apply_filters( 'yaymail_order_item_cost_colspan', 1, $this->element_data ), 'style' => [ 'min-width' => '65px', ], ], 'quantity' => [ 'label' => $this->titles['quantity'], 'col_span' => apply_filters( 'yaymail_order_item_quantity_colspan', 1, $this->element_data ), 'style' => [ 'min-width' => '85px', ], ], 'price' => [ 'label' => $this->titles['price'], 'col_span' => apply_filters( 'yaymail_order_item_price_colspan', 1, $this->element_data ), 'style' => [ 'word-wrap' => 'break-word', 'min-width' => '100px', 'width' => $this->show_product_item_cost ? '28%' : '38%', ], ], ], 'footer' => [ 'label_col_span' => $this->colspan_value, 'value_col_span' => 1, 'hidden_rows' => [], ], ] ); } public function render() { $style = $this->get_styles() . 'padding: 0;border-collapse: separate;'; ?> render_heading(); $this->render_order_items(); $this->render_footer(); ?>
get_styles(); $structure_table = $this->get_structure_table(); $structure_items = isset( $structure_table['items'] ) ? $structure_table['items'] : []; if ( isset( $structure_items['cost'] ) && ! $this->show_product_item_cost && ! $this->is_placeholder ) { unset( $structure_items['cost'] ); } ?> $structure_item ) : if ( isset( $structure_item['width'] ) ) { $width = 'width: ' . $structure_item['width'] . ';'; } else { $width = ''; } $item_style = isset( $structure_item['style'] ) ? $structure_item['style'] : []; if ( ! empty( $item_style ) ) { $item_style_string = TemplateHelpers::get_style( $item_style ); } else { $item_style_string = ''; } $column_style = $styles . $width . $item_style_string; echo '' . esc_html( $structure_item['label'] ) . ''; endforeach; ?> get_structure_table(); $structure_items = isset( $structure_table['items'] ) ? $structure_table['items'] : []; if ( isset( $structure_items['cost'] ) && ! $this->show_product_item_cost && ! $this->is_placeholder ) { unset( $structure_items['cost'] ); } ?> order || ! ( $this->order instanceof \WC_Order ) || 12345 === $this->order->get_id() ) { $this->render_sample_items( $structure_items ); } else { $this->render_real_items( $structure_items ); } ?> 'left' === $image_position && 'rtl' === $direction ? 'right' : 'left', ] ); $style = $this->get_styles(); $is_placeholder = $this->is_placeholder; $show_image = isset( $yaymail_settings['show_product_image'] ) ? boolval( $yaymail_settings['show_product_image'] ) : false; $image_height = isset( $yaymail_settings['product_image_height'] ) ? $yaymail_settings['product_image_height'] : '30'; $image_width = isset( $yaymail_settings['product_image_width'] ) ? $yaymail_settings['product_image_width'] : '30'; $show_image = isset( $yaymail_settings['show_product_image'] ) ? boolval( $yaymail_settings['show_product_image'] ) : false; $show_sku = isset( $yaymail_settings['show_product_sku'] ) ? boolval( $yaymail_settings['show_product_sku'] ) : false; $show_des = isset( $yaymail_settings['show_product_description'] ) ? boolval( $yaymail_settings['show_product_description'] ) : false; $show_regular_price = isset( $yaymail_settings['show_product_regular_price'] ) ? boolval( $yaymail_settings['show_product_regular_price'] ) : false; $show_hyper_links = isset( $yaymail_settings['show_product_hyper_links'] ) ? boolval( $yaymail_settings['show_product_hyper_links'] ) : false; $image_style = 'left' === $image_position ? $this->get_styles_product_image() . $style_image_position_left : $this->get_styles_product_image(); $image_url = wc_placeholder_img_src(); $image = $is_placeholder ? "product image" : "product image"; $sku = __( 'sku', 'yaymail' ); $short_description = __( 'Product short description', 'yaymail' ); $product_name = __( 'Happy YayCommerce', 'yaymail' ); $product_permalink = '#'; $product_hyper_link = "{$product_name}"; $product_cost = 9; $product_quantity = 2; $product_regular_price = 10; $is_layout_type_modern = isset( $this->element_data['layout_type'] ) && 'modern' === $this->element_data['layout_type']; ?> $structure_item ) : ?> " ); require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/image-content.php'; echo ( '' ); } ?>
" ); require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/image-content.php'; echo ( '
' ); } ?> x order, $this->element_data, true ) ); break; endswitch; ?> 'left' === $image_position && 'rtl' === $direction ? 'right' : 'left', ] ); $args_data = [ 'order' => $this->order, 'text_style' => $this->get_styles(), 'styles_product_image' => 'left' === $image_position ? $this->get_styles_product_image() . $style_image_position_left : $this->get_styles_product_image(), 'is_placeholder' => $this->is_placeholder, 'structure_items' => $structure_items, ]; // Just has data when send mail if ( ! empty( $this->element_data ) ) { $args_data['element'] = $this->element_data; } $path_data = apply_filters( 'yaymail_order_details_items', 'templates/shortcodes/order-details/order-items/main.php' ); $html = yaymail_get_content( $path_data, $args_data ); $allowed_html = TemplateHelpers::wp_kses_allowed_html(); echo wp_kses( $html, $allowed_html ); } public function render_footer() { $structure_table = $this->get_structure_table(); $structure_footer = isset( $structure_table['footer'] ) ? $structure_table['footer'] : []; if ( empty( $structure_footer ) ) { return; } // TODO: change class name ?> render_item_totals( $structure_footer ); if ( ! empty( $this->order ) && $this->order->get_customer_note() ) { $this->render_customer_note( $structure_footer ); } ?> element_data['custom_footer_rows'] ) ? $this->element_data['custom_footer_rows'] : []; // Group custom rows by zone $rows_by_zone = [ 'before_all' => [], 'after_subtotal' => [], 'before_total' => [], 'after_total' => [], ]; foreach ( $custom_rows as $row ) { // Check if row is enabled - handle both boolean and string values $is_enabled = isset( $row['enabled'] ) ? boolval( $row['enabled'] ) : false; if ( $is_enabled && isset( $row['zone'] ) ) { $zone = $row['zone']; if ( isset( $rows_by_zone[ $zone ] ) ) { $rows_by_zone[ $zone ][] = $row; } } } // Sort each zone by order foreach ( $rows_by_zone as &$zone_rows ) { usort( $zone_rows, function( $a, $b ) { $order_a = isset( $a['order'] ) ? intval( $a['order'] ) : 0; $order_b = isset( $b['order'] ) ? intval( $b['order'] ) : 0; return $order_a - $order_b; } ); } $index = 0; // ZONE 1: Before all foreach ( $rows_by_zone['before_all'] as $row ) { $this->render_custom_row( $row, $index++, $structure_footer ); } // Process standard rows foreach ( $this->item_totals as $key => $total ) { if ( in_array( $key, $structure_footer['hidden_rows'] ?? [], true ) ) { continue; } // ZONE 2: After subtotal if ( 'cart_subtotal' === $key ) { $this->render_standard_row( $key, $total, $index++, $structure_footer ); foreach ( $rows_by_zone['after_subtotal'] as $row ) { $this->render_custom_row( $row, $index++, $structure_footer ); } continue; } // ZONE 3: Before total if ( 'order_total' === $key ) { foreach ( $rows_by_zone['before_total'] as $row ) { $this->render_custom_row( $row, $index++, $structure_footer ); } $this->render_standard_row( $key, $total, $index++, $structure_footer ); continue; } // Other rows - render normally $this->render_standard_row( $key, $total, $index++, $structure_footer ); }//end foreach // ZONE 4: After all (after total) foreach ( $rows_by_zone['after_total'] as $row ) { $this->render_custom_row( $row, $index++, $structure_footer ); } } /** * Render a standard order total row * * @param string $key The order total key. * @param array $total The order total data. * @param int $index The row index. * @param array $structure_footer The footer structure data. */ private function render_standard_row( $key, $total, $index, $structure_footer ) { $tr_class = "yaymail-order-detail-row-{$key}"; $can_apply_placeholder = $this->is_placeholder && isset( $this->titles[ $key ] ); $label = TemplateHelpers::get_content_as_placeholder( "{$key}_title", esc_html( isset( $this->titles[ $key ] ) ? $this->titles[ $key ] : $total['label'] ), $can_apply_placeholder ); $style = $this->get_styles() . TemplateHelpers::get_style( [ 'border-top-width' => 1 === $index ? '4px' : '0', ] ); $heading_style = $style . 'font-size: ' . ( isset( $this->element_data['table_heading_font_size'] ) ? $this->element_data['table_heading_font_size'] : '14' ) . 'px;'; $content_style = $style . 'font-size: ' . ( isset( $this->element_data['table_content_font_size'] ) ? $this->element_data['table_content_font_size'] : '14' ) . 'px;'; ?> get_styles() . TemplateHelpers::get_style( [ 'border-top-width' => 1 === $index ? '4px' : '0', ] ); $heading_style = $style . 'font-size: ' . ( isset( $this->element_data['table_heading_font_size'] ) ? $this->element_data['table_heading_font_size'] : '14' ) . 'px;'; $content_style = $style . 'font-size: ' . ( isset( $this->element_data['table_content_font_size'] ) ? $this->element_data['table_content_font_size'] : '14' ) . 'px;'; $row_id = isset( $custom_row['id'] ) ? esc_attr( $custom_row['id'] ) : ''; ?> order_note ) ) : $style = $this->get_styles(); ?> titles['order_note'] ); ?> order_note ) ) ); ?>