Skip to content

Commit 241a9f9

Browse files
committed
Fix #456 YITH WooCommerce Product Add-Ons meta key is showing in addon.
Fix #456 YITH WooCommerce Product Add-Ons meta key is showing in addon.
1 parent 0ee3df0 commit 241a9f9

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,42 @@
209209
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
210210
}
211211
}
212+
// --- handle YITH add-ons: print labels and remove raw ywapo-* meta to avoid duplicates ---
213+
$yith_addon_meta_map = array();
214+
if ( isset( $item_meta_fields['_ywapo_meta_data'] ) && is_array( $item_meta_fields['_ywapo_meta_data'] ) ) {
215+
foreach ( $item_meta_fields['_ywapo_meta_data'] as $group ) {
216+
if ( ! is_array( $group ) ) {
217+
continue;
218+
}
219+
foreach ( (array) $group as $maybe ) {
220+
if ( isset( $maybe['addon_id'] ) ) {
221+
$option_id = isset( $maybe['option_id'] ) ? $maybe['option_id'] : 0;
222+
$meta_key = 'ywapo-addon-' . $maybe['addon_id'] . '-' . $option_id;
223+
$yith_addon_meta_map[ $meta_key ] = $maybe;
224+
} else {
225+
foreach ( (array) $maybe as $sub ) {
226+
if ( isset( $sub['addon_id'] ) ) {
227+
$option_id = isset( $sub['option_id'] ) ? $sub['option_id'] : 0;
228+
$meta_key = 'ywapo-addon-' . $sub['addon_id'] . '-' . $option_id;
229+
$yith_addon_meta_map[ $meta_key ] = $sub;
230+
}
231+
}
232+
}
233+
}
234+
}
235+
foreach ( $yith_addon_meta_map as $meta_key => $addon ) {
236+
if ( isset( $addon['display_label'] ) && isset( $addon['display_value'] ) ) {
237+
echo '<br><strong>' . esc_html( $addon['display_label'] ) . ' : </strong>' . wp_kses_post( $addon['display_value'] );
238+
} else {
239+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
240+
echo '<br><strong>' . esc_html( $meta_key ) . ' : </strong>' . wp_kses_post( $item_meta_fields[ $meta_key ] );
241+
}
242+
}
243+
if ( isset( $item_meta_fields[ $meta_key ] ) ) {
244+
unset( $item_meta_fields[ $meta_key ] );
245+
}
246+
}
247+
} // --- end handle YITH add-ons ---
212248
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
213249
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
214250
$variation = wc_get_product( $item['product_id'] );

templates/print-order/print-content.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,42 @@
166166
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
167167
}
168168
}
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 ---
169205
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
170206
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
171207
$variation = wc_get_product( $item['product_id'] );

0 commit comments

Comments
 (0)