html-order-item.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * Shows an order item
  4. *
  5. * @var object $item The item being displayed
  6. * @var int $item_id The id of the item being displayed
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. exit;
  10. }
  11. $product = $item->get_product();
  12. $product_link = $product ? admin_url( 'post.php?post=' . $item->get_product_id() . '&action=edit' ) : '';
  13. $thumbnail = $product ? apply_filters( 'woocommerce_admin_order_item_thumbnail', $product->get_image( 'thumbnail', array( 'title' => '' ), false ), $item_id, $item ) : '';
  14. $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empty( $class ) ? $class : '', $item, $order );
  15. ?>
  16. <tr class="item <?php echo esc_attr( $row_class ); ?>" data-order_item_id="<?php echo esc_attr( $item_id ); ?>">
  17. <td class="thumb">
  18. <?php echo '<div class="wc-order-item-thumbnail">' . wp_kses_post( $thumbnail ) . '</div>'; ?>
  19. </td>
  20. <td class="name" data-sort-value="<?php echo esc_attr( $item->get_name() ); ?>">
  21. <?php
  22. echo $product_link ? '<a href="' . esc_url( $product_link ) . '" class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</a>' : '<div class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</div>';
  23. if ( $product && $product->get_sku() ) {
  24. echo '<div class="wc-order-item-sku"><strong>' . esc_html__( 'SKU:', 'woocommerce' ) . '</strong> ' . esc_html( $product->get_sku() ) . '</div>';
  25. }
  26. if ( $item->get_variation_id() ) {
  27. echo '<div class="wc-order-item-variation"><strong>' . esc_html__( 'Variation ID:', 'woocommerce' ) . '</strong> ';
  28. if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) {
  29. echo esc_html( $item->get_variation_id() );
  30. } else {
  31. /* translators: %s: variation id */
  32. printf( esc_html__( '%s (No longer exists)', 'woocommerce' ), $item->get_variation_id() );
  33. }
  34. echo '</div>';
  35. }
  36. ?>
  37. <input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />
  38. <input type="hidden" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" value="<?php echo esc_attr( $item->get_tax_class() ); ?>" />
  39. <?php do_action( 'woocommerce_before_order_itemmeta', $item_id, $item, $product ); ?>
  40. <?php require 'html-order-item-meta.php'; ?>
  41. <?php do_action( 'woocommerce_after_order_itemmeta', $item_id, $item, $product ); ?>
  42. </td>
  43. <?php do_action( 'woocommerce_admin_order_item_values', $product, $item, absint( $item_id ) ); ?>
  44. <td class="item_cost" width="1%" data-sort-value="<?php echo esc_attr( $order->get_item_subtotal( $item, false, true ) ); ?>">
  45. <div class="view">
  46. <?php
  47. echo wc_price( $order->get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) );
  48. if ( $item->get_subtotal() !== $item->get_total() ) {
  49. echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
  50. }
  51. ?>
  52. </div>
  53. </td>
  54. <td class="quantity" width="1%">
  55. <div class="view">
  56. <?php
  57. echo '<small class="times">&times;</small> ' . esc_html( $item->get_quantity() );
  58. if ( $refunded_qty = $order->get_qty_refunded_for_item( $item_id ) ) {
  59. echo '<small class="refunded">-' . ( $refunded_qty * -1 ) . '</small>';
  60. }
  61. ?>
  62. </div>
  63. <div class="edit" style="display: none;">
  64. <input type="number" step="<?php echo esc_attr( apply_filters( 'woocommerce_quantity_input_step', '1', $product ) ); ?>" min="0" autocomplete="off" name="order_item_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" value="<?php echo esc_attr( $item->get_quantity() ); ?>" data-qty="<?php echo esc_attr( $item->get_quantity() ); ?>" size="4" class="quantity" />
  65. </div>
  66. <div class="refund" style="display: none;">
  67. <input type="number" step="<?php echo esc_attr( apply_filters( 'woocommerce_quantity_input_step', '1', $product ) ); ?>" min="0" max="<?php echo absint( $item->get_quantity() ); ?>" autocomplete="off" name="refund_order_item_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" size="4" class="refund_order_item_qty" />
  68. </div>
  69. </td>
  70. <td class="line_cost" width="1%" data-sort-value="<?php echo esc_attr( $item->get_total() ); ?>">
  71. <div class="view">
  72. <?php
  73. echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
  74. if ( $item->get_subtotal() !== $item->get_total() ) {
  75. echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
  76. }
  77. if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) {
  78. echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
  79. }
  80. ?>
  81. </div>
  82. <div class="edit" style="display: none;">
  83. <div class="split-input">
  84. <div class="input">
  85. <label><?php esc_attr_e( 'Pre-discount:', 'woocommerce' ); ?></label>
  86. <input type="text" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $item->get_subtotal() ) ); ?>" class="line_subtotal wc_input_price" data-subtotal="<?php echo esc_attr( wc_format_localized_price( $item->get_subtotal() ) ); ?>" />
  87. </div>
  88. <div class="input">
  89. <label><?php esc_attr_e( 'Total:', 'woocommerce' ); ?></label>
  90. <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $item->get_total() ) ); ?>" class="line_total wc_input_price" data-tip="<?php esc_attr_e( 'After pre-tax discounts.', 'woocommerce' ); ?>" data-total="<?php echo esc_attr( wc_format_localized_price( $item->get_total() ) ); ?>" />
  91. </div>
  92. </div>
  93. </div>
  94. <div class="refund" style="display: none;">
  95. <input type="text" name="refund_line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_total wc_input_price" />
  96. </div>
  97. </td>
  98. <?php
  99. if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
  100. foreach ( $order_taxes as $tax_item ) {
  101. $tax_item_id = $tax_item->get_rate_id();
  102. $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
  103. $tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : '';
  104. ?>
  105. <td class="line_tax" width="1%">
  106. <div class="view">
  107. <?php
  108. if ( '' !== $tax_item_total ) {
  109. echo wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) );
  110. } else {
  111. echo '&ndash;';
  112. }
  113. if ( $item->get_subtotal() !== $item->get_total() ) {
  114. if ( '' === $tax_item_total ) {
  115. echo '<span class="wc-order-item-discount">&ndash;</span>';
  116. } else {
  117. echo '<span class="wc-order-item-discount">-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . '</span>';
  118. }
  119. }
  120. if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id ) ) {
  121. echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
  122. }
  123. ?>
  124. </div>
  125. <div class="edit" style="display: none;">
  126. <div class="split-input">
  127. <div class="input">
  128. <label><?php esc_attr_e( 'Pre-discount:', 'woocommerce' ); ?></label>
  129. <input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" class="line_subtotal_tax wc_input_price" data-subtotal_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
  130. </div>
  131. <div class="input">
  132. <label><?php esc_attr_e( 'Total:', 'woocommerce' ); ?></label>
  133. <input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" class="line_tax wc_input_price" data-total_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
  134. </div>
  135. </div>
  136. </div>
  137. <div class="refund" style="display: none;">
  138. <input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
  139. </div>
  140. </td>
  141. <?php
  142. }
  143. }
  144. ?>
  145. <td class="wc-order-edit-line-item" width="1%">
  146. <div class="wc-order-edit-line-item-actions">
  147. <?php if ( $order->is_editable() ) : ?>
  148. <a class="edit-order-item tips" href="#" data-tip="<?php esc_attr_e( 'Edit item', 'woocommerce' ); ?>"></a><a class="delete-order-item tips" href="#" data-tip="<?php esc_attr_e( 'Delete item', 'woocommerce' ); ?>"></a>
  149. <?php endif; ?>
  150. </div>
  151. </td>
  152. </tr>