| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
use YayMail\Utils\TemplateHelpers; |
| 6 |
|
| 7 |
$text_align = yaymail_get_text_align(); |
| 8 |
$margin_side = is_rtl() ? 'left' : 'right'; |
| 9 |
$order_id = isset( $args['order'] ) ? $args['order']->get_id() : ''; |
| 10 |
$order_data = isset( $order_id ) ? wc_get_order( $order_id ) : ''; |
| 11 |
|
| 12 |
if ( empty( $order_data ) ) { |
| 13 |
$order_data = isset( $args['order'] ) ? $args['order'] : null; |
| 14 |
} |
| 15 |
|
| 16 |
$element_data = isset( $args['element'] ) ? $args['element'] : []; |
| 17 |
$border_color = isset( $element_data['border_color'] ) ? $element_data['border_color'] : 'inherit'; |
| 18 |
$text_style = isset( $args['text_style'] ) ? $args['text_style'] : ''; |
| 19 |
$image_style = isset( $args['styles_product_image'] ) ? $args['styles_product_image'] : ''; |
| 20 |
$is_placeholder = isset( $args['is_placeholder'] ) ? $args['is_placeholder'] : false; |
| 21 |
$structure_items = isset( $args['structure_items'] ) ? $args['structure_items'] : []; |
| 22 |
$yaymail_settings = yaymail_settings(); |
| 23 |
$order_items = ! empty( $order_data ) ? $order_data->get_items() : []; |
| 24 |
$image_height = isset( $yaymail_settings['product_image_height'] ) ? $yaymail_settings['product_image_height'] : '30'; |
| 25 |
$image_width = isset( $yaymail_settings['product_image_width'] ) ? $yaymail_settings['product_image_width'] : '30'; |
| 26 |
$image_position = isset( $yaymail_settings['product_image_position'] ) ? $yaymail_settings['product_image_position'] : 'top'; |
| 27 |
$show_image = isset( $yaymail_settings['show_product_image'] ) ? boolval( $yaymail_settings['show_product_image'] ) : false; |
| 28 |
$show_sku = isset( $yaymail_settings['show_product_sku'] ) ? boolval( $yaymail_settings['show_product_sku'] ) : false; |
| 29 |
$show_des = isset( $yaymail_settings['show_product_description'] ) ? boolval( $yaymail_settings['show_product_description'] ) : false; |
| 30 |
$show_hyper_links = isset( $yaymail_settings['show_product_hyper_links'] ) ? boolval( $yaymail_settings['show_product_hyper_links'] ) : false; |
| 31 |
$show_regular_price = isset( $yaymail_settings['show_product_regular_price'] ) ? boolval( $yaymail_settings['show_product_regular_price'] ) : false; |
| 32 |
|
| 33 |
$show_purchase_note = true; |
| 34 |
$purchase_note = true; |
| 35 |
|
| 36 |
$is_layout_type_modern = isset( $element_data['layout_type'] ) && 'modern' === $element_data['layout_type']; |
| 37 |
|
| 38 |
$count_items = 0; |
| 39 |
|
| 40 |
foreach ( $order_items as $item_id => $item ) : |
| 41 |
++$count_items; |
| 42 |
$product = $item->get_product(); |
| 43 |
$sku = ''; |
| 44 |
$purchase_note = ''; |
| 45 |
$image_url = wc_placeholder_img_src(); |
| 46 |
$image = $is_placeholder ? "<img width='{{product_image_width}}px' height='{{product_image_height}}px' src='{$image_url}' alt='product image'/>" : "<img width='{$image_width}px' height='{$image_height}px' src='{$image_url}' alt='product image'/>"; |
| 47 |
$short_description = ''; |
| 48 |
$product_name = $item->get_name(); |
| 49 |
$product_permalink = '#'; |
| 50 |
$product_hyper_link = "<a href='{$product_permalink}' target='_blank'>{$product_name}</a>"; |
| 51 |
$product_regular_price = ''; |
| 52 |
|
| 53 |
if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) { |
| 54 |
continue; |
| 55 |
} |
| 56 |
|
| 57 |
if ( is_object( $product ) ) { |
| 58 |
$sku = $product->get_sku(); |
| 59 |
$purchase_note = $product->get_purchase_note(); |
| 60 |
$image_url = current( wp_get_attachment_image_src( $product->get_image_id(), 'full' ) ? wp_get_attachment_image_src( $product->get_image_id(), 'full' ) : [ wc_placeholder_img_src() ] ); |
| 61 |
$image = $is_placeholder ? "<img style='margin-right:0;' width='{{product_image_width}}px' height='{{product_image_height}}px' src='{$image_url}' alt='product image'/>" : "<img style='margin-right:0; width: {$image_width}px; height: {$image_height}px;' src='{$image_url}' alt='product image'/>"; |
| 62 |
$short_description = $product->get_short_description(); |
| 63 |
$product_permalink = method_exists( $product, 'get_permalink' ) ? $product->get_permalink() : '#'; |
| 64 |
$product_hyper_link = "<a href='{$product_permalink}' target='_blank'>{$product_name}</a>"; |
| 65 |
$product_regular_price = isset( $product->get_data()['regular_price'] ) ? (float) $product->get_data()['regular_price'] : ''; |
| 66 |
} |
| 67 |
$row_classes = 'order_item'; |
| 68 |
if ( $count_items === count( $order_items ) ) { |
| 69 |
$row_classes .= ' yaymail-order-item-last'; |
| 70 |
} |
| 71 |
?> |
| 72 |
|
| 73 |
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', $row_classes, $item, $order_data ) ); ?>" style="<?php echo esc_attr( $text_style ); ?>;"> |
| 74 |
<?php |
| 75 |
foreach ( $structure_items as $key => $structure_item ) : |
| 76 |
if ( isset( $structure_item['width'] ) ) { |
| 77 |
$width = 'width: ' . $structure_item['width'] . ';'; |
| 78 |
} else { |
| 79 |
$width = ''; |
| 80 |
} |
| 81 |
$item_style = isset( $structure_item['style'] ) ? $structure_item['style'] : []; |
| 82 |
if ( ! empty( $item_style ) ) { |
| 83 |
$item_style_string = TemplateHelpers::get_style( $item_style ); |
| 84 |
} else { |
| 85 |
$item_style_string = ''; |
| 86 |
} |
| 87 |
|
| 88 |
$column_style = $text_style . $width . $item_style_string; |
| 89 |
?> |
| 90 |
<td colspan="<?php echo esc_attr( $structure_item['col_span'] ); ?>" class="td yaymail_item_<?php echo esc_attr( $key ); ?>_content" style="<?php echo esc_attr( $column_style ); ?>"> |
| 91 |
<?php |
| 92 |
switch ( $key ) : |
| 93 |
case 'product': |
| 94 |
// Show title/image etc. |
| 95 |
if ( $show_image && 'bottom' !== $image_position || $is_placeholder ) { |
| 96 |
echo wp_kses_post( "<div class='yaymail-product_image_position__top' style='{$image_style}'>" ); |
| 97 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/image-content.php'; |
| 98 |
echo ( '</div>' ); |
| 99 |
} |
| 100 |
?> |
| 101 |
|
| 102 |
<!-- Product details --> |
| 103 |
<div class='yaymail-product-details'> |
| 104 |
<?php |
| 105 |
|
| 106 |
// Product name. |
| 107 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/product-name-content.php'; |
| 108 |
|
| 109 |
// SKU. |
| 110 |
if ( ( $show_sku && ! empty( $sku ) ) || ( $is_placeholder && ! empty( $sku ) ) ) { |
| 111 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/sku-content.php'; |
| 112 |
} |
| 113 |
|
| 114 |
// Product Description. |
| 115 |
if ( ( $show_des && ! empty( $short_description ) ) || ( $is_placeholder && ! empty( $short_description ) ) ) { |
| 116 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/product-short-description-content.php'; |
| 117 |
} |
| 118 |
|
| 119 |
// allow other plugins to add additional product information here. |
| 120 |
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order_data, '' ); |
| 121 |
?> |
| 122 |
<div class="yaymail-wc-item-meta" style="clear:both"> |
| 123 |
<?php |
| 124 |
wc_display_item_meta( |
| 125 |
$item, |
| 126 |
[ |
| 127 |
'label_before' => '<strong class="wc-item-meta-label yaymail-item-meta-label" style="float: ' . esc_attr( $text_align ) . '; margin-' . esc_attr( $margin_side ) . ': .25em; clear: both">', |
| 128 |
] |
| 129 |
); |
| 130 |
?> |
| 131 |
</div> |
| 132 |
<?php |
| 133 |
|
| 134 |
// allow other plugins to add additional product information here. |
| 135 |
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order_data, '' ); |
| 136 |
|
| 137 |
// Show title/image etc in bottom. |
| 138 |
if ( ( $show_image && 'bottom' === $image_position ) || $is_placeholder ) { |
| 139 |
echo wp_kses_post( "<div class='yaymail-product_image_position__bottom' style='{$image_style}'>" ); |
| 140 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/image-content.php'; |
| 141 |
echo ( '</div>' ); |
| 142 |
} |
| 143 |
?> |
| 144 |
</div> |
| 145 |
<!-- End Product details --> |
| 146 |
<?php |
| 147 |
break; |
| 148 |
case 'cost': |
| 149 |
echo wp_kses_post( wc_price( $order_data->get_item_subtotal( $item, false, true ), [ 'currency' => $order_data->get_currency() ] ) ); |
| 150 |
break; |
| 151 |
case 'quantity': |
| 152 |
$qty = $item->get_quantity(); |
| 153 |
$refunded_qty = $order_data->get_qty_refunded_for_item( $item_id ); |
| 154 |
|
| 155 |
if ( $refunded_qty ) { |
| 156 |
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>'; |
| 157 |
} else { |
| 158 |
$qty_display = esc_html( $qty ); |
| 159 |
} |
| 160 |
?> |
| 161 |
<?php if ( $is_layout_type_modern || $is_placeholder ) : ?> |
| 162 |
<span class="yaymail-quantity-type-modern">x</span> |
| 163 |
<?php endif; ?> |
| 164 |
<?php |
| 165 |
echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) ); |
| 166 |
break; |
| 167 |
case 'price': |
| 168 |
// Show product regular price. |
| 169 |
if ( ( $show_regular_price && ! empty( $product_regular_price ) ) || ( $is_placeholder && ! empty( $product_regular_price ) ) ) { |
| 170 |
require YAYMAIL_PLUGIN_PATH . 'templates/shortcodes/order-details/order-items/product-regular-price-content.php'; |
| 171 |
} |
| 172 |
echo wp_kses_post( $order_data->get_formatted_line_subtotal( $item ) ); |
| 173 |
break; |
| 174 |
default: |
| 175 |
yaymail_kses_post_e( do_action( 'yaymail_order_details_item_' . $key . '_content', $item, $order_data, $element_data, false ) ); |
| 176 |
break; |
| 177 |
endswitch; |
| 178 |
?> |
| 179 |
</td> |
| 180 |
<?php endforeach; ?> |
| 181 |
</tr> |
| 182 |
<?php |
| 183 |
|
| 184 |
if ( $show_purchase_note && $purchase_note ) { |
| 185 |
?> |
| 186 |
<tr> |
| 187 |
<td class="yaymail-purchase-note" colspan="<?php echo isset( $structure_items['cost'] ) ? 3 : 2; ?>" style="<?php echo esc_attr( $text_style ); ?>;"> |
| 188 |
<?php |
| 189 |
echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) ); |
| 190 |
?> |
| 191 |
</td> |
| 192 |
</tr> |
| 193 |
<?php |
| 194 |
} |
| 195 |
?> |
| 196 |
|
| 197 |
<?php endforeach; ?> |
| 198 |
|