Skip to content

Commit 9fdbce4

Browse files
authored
Merge branch 'master' into fix-457
2 parents 5eb4d93 + 4544f74 commit 9fdbce4

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

includes/admin/views/Preview_template/default-preview-template.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
</span>
198198

199199
<?php
200-
$item_meta_fields = wc_display_item_meta( $item, apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item ) );
200+
$item_meta_fields = apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item );
201201
if ( null === $item_meta_fields ) {
202202
$item_meta_fields = array();
203203
}
@@ -209,7 +209,44 @@
209209
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
210210
}
211211
}
212-
// Extra Product Options (ThemeComplete EPO) support.
212+
213+
// --- handle YITH add-ons: print labels and remove raw ywapo-* meta to avoid duplicates ---
214+
$yith_addon_meta_map = array();
215+
if ( isset( $item_meta_fields['_ywapo_meta_data'] ) && is_array( $item_meta_fields['_ywapo_meta_data'] ) ) {
216+
foreach ( $item_meta_fields['_ywapo_meta_data'] as $group ) {
217+
if ( ! is_array( $group ) ) {
218+
continue;
219+
}
220+
foreach ( (array) $group as $maybe ) {
221+
if ( isset( $maybe['addon_id'] ) ) {
222+
$option_id = isset( $maybe['option_id'] ) ? $maybe['option_id'] : 0;
223+
$meta_key = 'ywapo-addon-' . $maybe['addon_id'] . '-' . $option_id;
224+
$yith_addon_meta_map[ $meta_key ] = $maybe;
225+
} else {
226+
foreach ( (array) $maybe as $sub ) {
227+
if ( isset( $sub['addon_id'] ) ) {
228+
$option_id = isset( $sub['option_id'] ) ? $sub['option_id'] : 0;
229+
$meta_key = 'ywapo-addon-' . $sub['addon_id'] . '-' . $option_id;
230+
$yith_addon_meta_map[ $meta_key ] = $sub;
231+
}
232+
}
233+
}
234+
}
235+
}
236+
foreach ( $yith_addon_meta_map as $meta_key => $addon ) {
237+
if ( isset( $addon['display_label'] ) && isset( $addon['display_value'] ) ) {
238+
echo '<br><strong>' . esc_html( $addon['display_label'] ) . ' : </strong>' . wp_kses_post( $addon['display_value'] );
239+
} else {
240+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
241+
echo '<br><strong>' . esc_html( $meta_key ) . ' : </strong>' . wp_kses_post( $item_meta_fields[ $meta_key ] );
242+
}
243+
}
244+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
245+
unset( $item_meta_fields[ $meta_key ] );
246+
}
247+
}
248+
} // --- end handle YITH add-ons ---
249+
// Extra Product Options (ThemeComplete EPO) support.
213250
$epo_data = $item->get_meta( '_tmcartepo_data', true );
214251
if ( ! empty( $epo_data ) && is_array( $epo_data ) ) {
215252
foreach ( $epo_data as $epo ) {
@@ -218,6 +255,7 @@
218255
}
219256
}
220257
}
258+
221259
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
222260
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
223261
$variation = wc_get_product( $item['product_id'] );
@@ -238,9 +276,9 @@
238276
}
239277
}
240278
if ( isset( $term_wp->name ) ) {
241-
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
279+
echo '<br>' . wp_kses_post( '<strong>' . $attribute_name . ' : </strong>' . $term_wp->name );
242280
} else {
243-
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
281+
echo '<br>' . wp_kses_post( '<strong>' . $attribute_name . ' : </strong>' . $value );
244282
}
245283
}
246284
}
@@ -259,7 +297,7 @@
259297
}
260298
}
261299
}
262-
echo '<br>' . wp_kses_post( $key . ':' . $value );
300+
echo '<br>' . wp_kses_post( '<strong>' . wc_attribute_label( $key ) . '</strong> : ' . $value );
263301
}
264302
}
265303
}

templates/print-order/print-content.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
</span>
155155

156156
<?php
157-
$item_meta_fields = wc_display_item_meta( $item, apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item ) );
157+
$item_meta_fields = apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item );
158158
if ( null === $item_meta_fields ) {
159159
$item_meta_fields = array();
160160
}
@@ -166,7 +166,43 @@
166166
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
167167
}
168168
}
169-
// Extra Product Options (ThemeComplete EPO) support.
169+
// --- handle YITH add-ons: print labels and remove raw ywapo-* meta to avoid duplicates ---
170+
$yith_addon_meta_map = array();
171+
if ( isset( $item_meta_fields['_ywapo_meta_data'] ) && is_array( $item_meta_fields['_ywapo_meta_data'] ) ) {
172+
foreach ( $item_meta_fields['_ywapo_meta_data'] as $group ) {
173+
if ( ! is_array( $group ) ) {
174+
continue;
175+
}
176+
foreach ( (array) $group as $maybe ) {
177+
if ( isset( $maybe['addon_id'] ) ) {
178+
$option_id = isset( $maybe['option_id'] ) ? $maybe['option_id'] : 0;
179+
$meta_key = 'ywapo-addon-' . $maybe['addon_id'] . '-' . $option_id;
180+
$yith_addon_meta_map[ $meta_key ] = $maybe;
181+
} else {
182+
foreach ( (array) $maybe as $sub ) {
183+
if ( isset( $sub['addon_id'] ) ) {
184+
$option_id = isset( $sub['option_id'] ) ? $sub['option_id'] : 0;
185+
$meta_key = 'ywapo-addon-' . $sub['addon_id'] . '-' . $option_id;
186+
$yith_addon_meta_map[ $meta_key ] = $sub;
187+
}
188+
}
189+
}
190+
}
191+
}
192+
foreach ( $yith_addon_meta_map as $meta_key => $addon ) {
193+
if ( isset( $addon['display_label'] ) && isset( $addon['display_value'] ) ) {
194+
echo '<br><strong>' . esc_html( $addon['display_label'] ) . ' : </strong>' . wp_kses_post( $addon['display_value'] );
195+
} else {
196+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
197+
echo '<br><strong>' . esc_html( $meta_key ) . ' : </strong>' . wp_kses_post( $item_meta_fields[ $meta_key ] );
198+
}
199+
}
200+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
201+
unset( $item_meta_fields[ $meta_key ] );
202+
}
203+
}
204+
} // --- end handle YITH add-ons ---
205+
// Extra Product Options (ThemeComplete EPO) support.
170206
$epo_data = $item->get_meta( '_tmcartepo_data', true );
171207
if ( ! empty( $epo_data ) && is_array( $epo_data ) ) {
172208
foreach ( $epo_data as $epo ) {
@@ -175,6 +211,7 @@
175211
}
176212
}
177213
}
214+
178215
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
179216
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
180217
$variation = wc_get_product( $item['product_id'] );
@@ -195,9 +232,9 @@
195232
}
196233
}
197234
if ( isset( $term_wp->name ) ) {
198-
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
235+
echo '<br>' . wp_kses_post( '<strong>' . $attribute_name . ' : </strong>' . $term_wp->name );
199236
} else {
200-
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
237+
echo '<br>' . wp_kses_post( '<strong>' . $attribute_name . ' : </strong>' . $value );
201238
}
202239
}
203240
}
@@ -216,7 +253,7 @@
216253
}
217254
}
218255
}
219-
echo '<br>' . wp_kses_post( $key . ':' . $value );
256+
echo '<br>' . wp_kses_post( '<strong>' . wc_attribute_label( $key ) . '</strong> : ' . $value );
220257
}
221258
}
222259
}

0 commit comments

Comments
 (0)