Skip to content

Commit 0ee3df0

Browse files
authored
Merge pull request #459 from TycheSoftwares/revert-452-fix-451
Revert "Fix #451 variation item meta issue."
2 parents 051fc73 + b9b7975 commit 0ee3df0

File tree

2 files changed

+222
-2
lines changed

2 files changed

+222
-2
lines changed

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

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,117 @@
175175
<tr>
176176
<td class="product-name">
177177
<?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?>
178-
<?php wcdn_get_product_name( $product, $order, $item ); ?>
178+
<span class="name">
179+
<?php
180+
181+
$addon_name = $item->get_meta( '_wc_pao_addon_name', true );
182+
$addon_value = $item->get_meta( '_wc_pao_addon_value', true );
183+
$is_addon = ! empty( $addon_value );
184+
185+
if ( $is_addon ) { // Displaying options of product addon.
186+
$addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
187+
188+
echo wp_kses_post( $addon_html );
189+
} else {
190+
191+
$product_id = $item['product_id'];
192+
$prod_name = get_post( $product_id );
193+
$product_name = $prod_name->post_title;
194+
195+
echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
196+
?>
197+
</span>
198+
199+
<?php
200+
$item_meta_fields = wc_display_item_meta( $item, apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item ) );
201+
if ( null === $item_meta_fields ) {
202+
$item_meta_fields = array();
203+
}
204+
$product_addons = array();
205+
$woocommerce_product_addon = 'woocommerce-product-addons/woocommerce-product-addons.php';
206+
if ( in_array( $woocommerce_product_addon, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) ) {
207+
$product_id = $item['product_id'];
208+
if ( class_exists( 'WC_Product_Addons_Helper' ) ) {
209+
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
210+
}
211+
}
212+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
213+
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
214+
$variation = wc_get_product( $item['product_id'] );
215+
foreach ( $item_meta_fields as $key => $value ) {
216+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
217+
if ( is_array( $value ) ) {
218+
continue;
219+
}
220+
$term_wp = get_term_by( 'slug', $value, $key );
221+
$attribute_name = wc_attribute_label( $key, $variation );
222+
if ( ! empty( $product_addons ) ) {
223+
foreach ( $product_addons as $addon ) {
224+
if ( 'file_upload' === $addon['type'] ) {
225+
if ( $key === $addon['name'] ) {
226+
$value = wp_basename( $value );
227+
}
228+
}
229+
}
230+
}
231+
if ( isset( $term_wp->name ) ) {
232+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
233+
} else {
234+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
235+
}
236+
}
237+
}
238+
} else {
239+
foreach ( $item_meta_fields as $key => $value ) {
240+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
241+
if ( is_array( $value ) ) {
242+
continue;
243+
}
244+
if ( ! empty( $product_addons ) ) {
245+
foreach ( $product_addons as $addon ) {
246+
if ( 'file_upload' === $addon['type'] ) {
247+
if ( $key === $addon['name'] ) {
248+
$value = wp_basename( $value );
249+
}
250+
}
251+
}
252+
}
253+
echo '<br>' . wp_kses_post( $key . ':' . $value );
254+
}
255+
}
256+
}
257+
} else {
258+
$item_meta_new = new WC_Order_Item_Meta( $item_meta_fields, $product );
259+
$item_meta_new->display();
260+
261+
}
262+
?>
263+
<dl class="extras">
264+
<?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
265+
266+
<dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
267+
<dd>
268+
<?php
269+
// translators: files count.
270+
printf( esc_attr__( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
271+
?>
272+
</dd>
273+
274+
<?php endif; ?>
275+
276+
<?php
277+
wcdn_print_extra_fields( $item );
278+
$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order, $item );
279+
280+
foreach ( $fields as $field ) :
281+
?>
282+
283+
<dt><?php echo esc_html( $field['label'] ); ?></dt>
284+
<dd><?php echo esc_html( $field['value'] ); ?></dd>
285+
286+
<?php endforeach; ?>
287+
</dl>
288+
<?php } ?>
179289
<?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?>
180290
</td>
181291
<td class="product-item-price">

templates/print-order/print-content.php

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,117 @@
132132
<tr>
133133
<td class="product-name">
134134
<?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?>
135-
<?php wcdn_get_product_name( $product, $order, $item ); ?>
135+
<span class="name">
136+
<?php
137+
138+
$addon_name = $item->get_meta( '_wc_pao_addon_name', true );
139+
$addon_value = $item->get_meta( '_wc_pao_addon_value', true );
140+
$is_addon = ! empty( $addon_value );
141+
142+
if ( $is_addon ) { // Displaying options of product addon.
143+
$addon_html = '<div class="wc-pao-order-item-name">' . esc_html( $addon_name ) . '</div><div class="wc-pao-order-item-value">' . esc_html( $addon_value ) . '</div></div>';
144+
145+
echo wp_kses_post( $addon_html );
146+
} else {
147+
148+
$product_id = $item['product_id'];
149+
$prod_name = get_post( $product_id );
150+
$product_name = $prod_name->post_title;
151+
152+
echo wp_kses_post( apply_filters( 'wcdn_order_item_name', $product_name, $item ) );
153+
?>
154+
</span>
155+
156+
<?php
157+
$item_meta_fields = wc_display_item_meta( $item, apply_filters( 'wcdn_product_meta_data', $item['item_meta'], $item ) );
158+
if ( null === $item_meta_fields ) {
159+
$item_meta_fields = array();
160+
}
161+
$product_addons = array();
162+
$woocommerce_product_addon = 'woocommerce-product-addons/woocommerce-product-addons.php';
163+
if ( in_array( $woocommerce_product_addon, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ), true ) ) {
164+
$product_id = $item['product_id'];
165+
if ( class_exists( 'WC_Product_Addons_Helper' ) ) {
166+
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_id );
167+
}
168+
}
169+
if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', '>=' ) ) {
170+
if ( isset( $item['variation_id'] ) && 0 !== $item['variation_id'] ) {
171+
$variation = wc_get_product( $item['product_id'] );
172+
foreach ( $item_meta_fields as $key => $value ) {
173+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
174+
if ( is_array( $value ) ) {
175+
continue;
176+
}
177+
$term_wp = get_term_by( 'slug', $value, $key );
178+
$attribute_name = wc_attribute_label( $key, $variation );
179+
if ( ! empty( $product_addons ) ) {
180+
foreach ( $product_addons as $addon ) {
181+
if ( 'file_upload' === $addon['type'] ) {
182+
if ( $key === $addon['name'] ) {
183+
$value = wp_basename( $value );
184+
}
185+
}
186+
}
187+
}
188+
if ( isset( $term_wp->name ) ) {
189+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $term_wp->name );
190+
} else {
191+
echo '<br>' . wp_kses_post( $attribute_name . ':' . $value );
192+
}
193+
}
194+
}
195+
} else {
196+
foreach ( $item_meta_fields as $key => $value ) {
197+
if ( ! ( 0 === strpos( $key, '_' ) ) ) {
198+
if ( is_array( $value ) ) {
199+
continue;
200+
}
201+
if ( ! empty( $product_addons ) ) {
202+
foreach ( $product_addons as $addon ) {
203+
if ( 'file_upload' === $addon['type'] ) {
204+
if ( $key === $addon['name'] ) {
205+
$value = wp_basename( $value );
206+
}
207+
}
208+
}
209+
}
210+
echo '<br>' . wp_kses_post( $key . ':' . $value );
211+
}
212+
}
213+
}
214+
} else {
215+
$item_meta_new = new WC_Order_Item_Meta( $item_meta_fields, $product );
216+
$item_meta_new->display();
217+
218+
}
219+
?>
220+
<dl class="extras">
221+
<?php if ( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
222+
223+
<dt><?php esc_attr_e( 'Download:', 'woocommerce-delivery-notes' ); ?></dt>
224+
<dd>
225+
<?php
226+
// translators: files count.
227+
printf( esc_attr__( '%s Files', 'woocommerce-delivery-notes' ), count( $item->get_item_downloads() ) );
228+
?>
229+
</dd>
230+
231+
<?php endif; ?>
232+
233+
<?php
234+
wcdn_print_extra_fields( $item );
235+
$fields = apply_filters( 'wcdn_order_item_fields', array(), $product, $order, $item );
236+
237+
foreach ( $fields as $field ) :
238+
?>
239+
240+
<dt><?php echo esc_html( $field['label'] ); ?></dt>
241+
<dd><?php echo esc_html( $field['value'] ); ?></dd>
242+
243+
<?php endforeach; ?>
244+
</dl>
245+
<?php } ?>
136246
<?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?>
137247
</td>
138248
<td class="product-item-price">

0 commit comments

Comments
 (0)