/includes/admin/meta-boxes/views/html-order-items.php

  1. <?php 
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) { 
  4. exit; // Exit if accessed directly 
  5.  
  6. global $wpdb; 
  7.  
  8. // Get the payment gateway 
  9. $payment_gateway = wc_get_payment_gateway_by_order( $order ); 
  10.  
  11. // Get line items 
  12. $line_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', 'line_item' ) ); 
  13. $line_items_fee = $order->get_items( 'fee' ); 
  14. $line_items_shipping = $order->get_items( 'shipping' ); 
  15.  
  16. if ( wc_tax_enabled() ) { 
  17. $order_taxes = $order->get_taxes(); 
  18. $tax_classes = WC_Tax::get_tax_classes(); 
  19. $classes_options = wc_get_product_tax_class_options(); 
  20. $show_tax_columns = sizeof( $order_taxes ) === 1; 
  21. ?> 
  22. <div class="woocommerce_order_items_wrapper wc-order-items-editable"> 
  23. <table cellpadding="0" cellspacing="0" class="woocommerce_order_items"> 
  24. <thead> 
  25. <tr> 
  26. <th class="item sortable" colspan="2" data-sort="string-ins"><?php _e( 'Item', 'woocommerce' ); ?></th> 
  27. <?php do_action( 'woocommerce_admin_order_item_headers', $order ); ?> 
  28. <th class="item_cost sortable" data-sort="float"><?php _e( 'Cost', 'woocommerce' ); ?></th> 
  29. <th class="quantity sortable" data-sort="int"><?php _e( 'Qty', 'woocommerce' ); ?></th> 
  30. <th class="line_cost sortable" data-sort="float"><?php _e( 'Total', 'woocommerce' ); ?></th> 
  31. <?php 
  32. if ( ! empty( $order_taxes ) ) : 
  33. foreach ( $order_taxes as $tax_id => $tax_item ) : 
  34. $tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] ); 
  35. $tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' ); 
  36. $column_label = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'woocommerce' ); 
  37. $column_tip = sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $tax_item['name'], $tax_class_name ); 
  38. ?> 
  39. <th class="line_tax tips" data-tip="<?php echo esc_attr( $column_tip ); ?>"> 
  40. <?php echo esc_attr( $column_label ); ?> 
  41. <input type="hidden" class="order-tax-id" name="order_taxes[<?php echo $tax_id; ?>]" value="<?php echo esc_attr( $tax_item['rate_id'] ); ?>"> 
  42. <a class="delete-order-tax" href="#" data-rate_id="<?php echo $tax_id; ?>"></a> 
  43. </th> 
  44. <?php 
  45. endforeach; 
  46. endif; 
  47. ?> 
  48. <th class="wc-order-edit-line-item" width="1%"> </th> 
  49. </tr> 
  50. </thead> 
  51. <tbody id="order_line_items"> 
  52. <?php 
  53. foreach ( $line_items as $item_id => $item ) { 
  54. do_action( 'woocommerce_before_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); 
  55.  
  56. include( 'html-order-item.php' ); 
  57.  
  58. do_action( 'woocommerce_order_item_' . $item->get_type() . '_html', $item_id, $item, $order ); 
  59. do_action( 'woocommerce_admin_order_items_after_line_items', $order->get_id() ); 
  60. ?> 
  61. </tbody> 
  62. <tbody id="order_shipping_line_items"> 
  63. <?php 
  64. $shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array(); 
  65. foreach ( $line_items_shipping as $item_id => $item ) { 
  66. include( 'html-order-shipping.php' ); 
  67. do_action( 'woocommerce_admin_order_items_after_shipping', $order->get_id() ); 
  68. ?> 
  69. </tbody> 
  70. <tbody id="order_fee_line_items"> 
  71. <?php 
  72. foreach ( $line_items_fee as $item_id => $item ) { 
  73. include( 'html-order-fee.php' ); 
  74. do_action( 'woocommerce_admin_order_items_after_fees', $order->get_id() ); 
  75. ?> 
  76. </tbody> 
  77. <tbody id="order_refunds"> 
  78. <?php 
  79. if ( $refunds = $order->get_refunds() ) { 
  80. foreach ( $refunds as $refund ) { 
  81. include( 'html-order-refund.php' ); 
  82. do_action( 'woocommerce_admin_order_items_after_refunds', $order->get_id() ); 
  83. ?> 
  84. </tbody> 
  85. </table> 
  86. </div> 
  87. <div class="wc-order-data-row wc-order-item-bulk-edit" style="display:none;"> 
  88. <button type="button" class="button bulk-delete-items"><?php _e( 'Delete selected row(s)', 'woocommerce' ); ?></button> 
  89. <button type="button" class="button bulk-decrease-stock"><?php _e( 'Reduce stock', 'woocommerce' ); ?></button> 
  90. <button type="button" class="button bulk-increase-stock"><?php _e( 'Increase stock', 'woocommerce' ); ?></button> 
  91. <?php do_action( 'woocommerce_admin_order_item_bulk_actions', $order ); ?> 
  92. </div> 
  93. <div class="wc-order-data-row wc-order-totals-items wc-order-items-editable"> 
  94. <?php 
  95. $coupons = $order->get_items( array( 'coupon' ) ); 
  96. if ( $coupons ) { 
  97. ?> 
  98. <div class="wc-used-coupons"> 
  99. <ul class="wc_coupon_list"><?php 
  100. echo '<li><strong>' . __( 'Coupon(s)', 'woocommerce' ) . '</strong></li>'; 
  101. foreach ( $coupons as $item_id => $item ) { 
  102. $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) ); 
  103. $link = $post_id ? add_query_arg( array( 'post' => $post_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) : add_query_arg( array( 's' => $item->get_code(), 'post_status' => 'all', 'post_type' => 'shop_coupon' ), admin_url( 'edit.php' ) ); 
  104.  
  105. echo '<li class="code"><a href="' . esc_url( $link ) . '" class="tips" data-tip="' . esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ) . '"><span>' . esc_html( $item->get_code() ) . '</span></a></li>'; 
  106. ?></ul> 
  107. </div> 
  108. <?php 
  109. ?> 
  110. <table class="wc-order-totals"> 
  111. <tr> 
  112. <td class="label"><?php echo wc_help_tip( __( 'This is the total discount. Discounts are defined per line item.', 'woocommerce' ) ); ?> <?php _e( 'Discount:', 'woocommerce' ); ?></td> 
  113. <td width="1%"></td> 
  114. <td class="total"> 
  115. <?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); ?> 
  116. </td> 
  117. </tr> 
  118.  
  119. <?php do_action( 'woocommerce_admin_order_totals_after_discount', $order->get_id() ); ?> 
  120.  
  121. <tr> 
  122. <td class="label"><?php echo wc_help_tip( __( 'This is the shipping and handling total costs for the order.', 'woocommerce' ) ); ?> <?php _e( 'Shipping:', 'woocommerce' ); ?></td> 
  123. <td width="1%"></td> 
  124. <td class="total"><?php 
  125. if ( ( $refunded = $order->get_total_shipping_refunded() ) > 0 ) { 
  126. echo '<del>' . strip_tags( wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ) ) . '</del> <ins>' . wc_price( $order->get_shipping_total() - $refunded, array( 'currency' => $order->get_currency() ) ) . '</ins>'; 
  127. } else { 
  128. echo wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ); 
  129. ?></td> 
  130. </tr> 
  131.  
  132. <?php do_action( 'woocommerce_admin_order_totals_after_shipping', $order->get_id() ); ?> 
  133.  
  134. <?php if ( wc_tax_enabled() ) : ?> 
  135. <?php foreach ( $order->get_tax_totals() as $code => $tax ) : ?> 
  136. <tr> 
  137. <td class="label"><?php echo $tax->label; ?>:</td> 
  138. <td width="1%"></td> 
  139. <td class="total"><?php 
  140. if ( ( $refunded = $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ) > 0 ) { 
  141. echo '<del>' . strip_tags( $tax->formatted_amount ) . '</del> <ins>' . wc_price( WC_Tax::round( $tax->amount, wc_get_price_decimals() ) - WC_Tax::round( $refunded, wc_get_price_decimals() ), array( 'currency' => $order->get_currency() ) ) . '</ins>'; 
  142. } else { 
  143. echo $tax->formatted_amount; 
  144. ?></td> 
  145. </tr> 
  146. <?php endforeach; ?> 
  147. <?php endif; ?> 
  148.  
  149. <?php do_action( 'woocommerce_admin_order_totals_after_tax', $order->get_id() ); ?> 
  150.  
  151. <tr> 
  152. <td class="label"><?php _e( 'Order total', 'woocommerce' ); ?>:</td> 
  153. <td width="1%"></td> 
  154. <td class="total"> 
  155. <?php echo $order->get_formatted_order_total(); ?> 
  156. </td> 
  157. </tr> 
  158.  
  159. <?php do_action( 'woocommerce_admin_order_totals_after_total', $order->get_id() ); ?> 
  160.  
  161. <?php if ( $order->get_total_refunded() ) : ?> 
  162. <tr> 
  163. <td class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</td> 
  164. <td width="1%"></td> 
  165. <td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td> 
  166. </tr> 
  167. <?php endif; ?> 
  168.  
  169. <?php do_action( 'woocommerce_admin_order_totals_after_refunded', $order->get_id() ); ?> 
  170.  
  171. </table> 
  172. <div class="clear"></div> 
  173. </div> 
  174. <div class="wc-order-data-row wc-order-bulk-actions wc-order-data-row-toggle"> 
  175. <p class="add-items"> 
  176. <?php if ( $order->is_editable() ) : ?> 
  177. <button type="button" class="button add-line-item"><?php _e( 'Add item(s)', 'woocommerce' ); ?></button> 
  178. <?php else : ?> 
  179. <span class="description"><?php echo wc_help_tip( __( 'To edit this order change the status back to "Pending"', 'woocommerce' ) ); ?> <?php _e( 'This order is no longer editable.', 'woocommerce' ); ?></span> 
  180. <?php endif; ?> 
  181. <?php if ( wc_tax_enabled() && $order->is_editable() ) : ?> 
  182. <button type="button" class="button add-order-tax"><?php _e( 'Add tax', 'woocommerce' ); ?></button> 
  183. <?php endif; ?> 
  184. <?php if ( 0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded() ) ) : ?> 
  185. <button type="button" class="button refund-items"><?php _e( 'Refund', 'woocommerce' ); ?></button> 
  186. <?php endif; ?> 
  187. <?php 
  188. // allow adding custom buttons 
  189. do_action( 'woocommerce_order_item_add_action_buttons', $order ); 
  190. ?> 
  191. <?php if ( $order->is_editable() ) : ?> 
  192. <button type="button" class="button button-primary calculate-action"><?php _e( 'Recalculate', 'woocommerce' ); ?></button> 
  193. <?php endif; ?> 
  194. </p> 
  195. </div> 
  196. <div class="wc-order-data-row wc-order-add-item wc-order-data-row-toggle" style="display:none;"> 
  197. <button type="button" class="button add-order-item"><?php _e( 'Add product(s)', 'woocommerce' ); ?></button> 
  198. <button type="button" class="button add-order-fee"><?php _e( 'Add fee', 'woocommerce' ); ?></button> 
  199. <button type="button" class="button add-order-shipping"><?php _e( 'Add shipping cost', 'woocommerce' ); ?></button> 
  200. <?php 
  201. // allow adding custom buttons 
  202. do_action( 'woocommerce_order_item_add_line_buttons', $order ); 
  203. ?> 
  204. <button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button> 
  205. <button type="button" class="button button-primary save-action"><?php _e( 'Save', 'woocommerce' ); ?></button> 
  206. </div> 
  207. <?php if ( 0 < $order->get_total() - $order->get_total_refunded() || 0 < absint( $order->get_item_count() - $order->get_item_count_refunded() ) ) : ?> 
  208. <div class="wc-order-data-row wc-order-refund-items wc-order-data-row-toggle" style="display: none;"> 
  209. <table class="wc-order-totals"> 
  210. <tr style="display:none;"> 
  211. <td class="label"><label for="restock_refunded_items"><?php _e( 'Restock refunded items', 'woocommerce' ); ?>:</label></td> 
  212. <td class="total"><input type="checkbox" id="restock_refunded_items" name="restock_refunded_items" checked="checked" /></td> 
  213. </tr> 
  214. <tr> 
  215. <td class="label"><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</td> 
  216. <td class="total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td> 
  217. </tr> 
  218. <tr> 
  219. <td class="label"><?php _e( 'Total available to refund', 'woocommerce' ); ?>:</td> 
  220. <td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td> 
  221. </tr> 
  222. <tr> 
  223. <td class="label"><label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label></td> 
  224. <td class="total"> 
  225. <input type="text" class="text" id="refund_amount" name="refund_amount" class="wc_input_price" /> 
  226. <div class="clear"></div> 
  227. </td> 
  228. </tr> 
  229. <tr> 
  230. <td class="label"><label for="refund_reason"><?php echo wc_help_tip( __( 'Note: the refund reason will be visible by the customer.', 'woocommerce' ) ); ?> <?php _e( 'Reason for refund (optional):', 'woocommerce' ); ?></label></td> 
  231. <td class="total"> 
  232. <input type="text" class="text" id="refund_reason" name="refund_reason" /> 
  233. <div class="clear"></div> 
  234. </td> 
  235. </tr> 
  236. </table> 
  237. <div class="clear"></div> 
  238. <div class="refund-actions"> 
  239. <?php 
  240. $refund_amount = '<span class="wc-order-refund-amount">' . wc_price( 0, array( 'currency' => $order->get_currency() ) ) . '</span>'; 
  241. $gateway_supports_refunds = false !== $payment_gateway && $payment_gateway->supports( 'refunds' ); 
  242. $gateway_name = false !== $payment_gateway ? ( ! empty( $payment_gateway->method_title ) ? $payment_gateway->method_title : $payment_gateway->get_title() ) : __( 'Payment gateway', 'woocommerce' ); 
  243. ?> 
  244. <button type="button" class="button <?php echo $gateway_supports_refunds ? 'button-primary do-api-refund' : 'tips disabled'; ?>" <?php echo $gateway_supports_refunds ? '' : 'data-tip="' . esc_attr__( 'The payment gateway used to place this order does not support automatic refunds.', 'woocommerce' ) . '"'; ?>><?php printf( __( 'Refund %1$s via %2$s', 'woocommerce' ), $refund_amount, $gateway_name ); ?></button> 
  245. <button type="button" class="button button-primary do-manual-refund tips" data-tip="<?php esc_attr_e( 'You will need to manually issue a refund through your payment gateway after using this.', 'woocommerce' ); ?>"><?php printf( __( 'Refund %s manually', 'woocommerce' ), $refund_amount ); ?></button> 
  246. <button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button> 
  247. <div class="clear"></div> 
  248. </div> 
  249. </div> 
  250. <?php endif; ?> 
  251.  
  252. <script type="text/template" id="tmpl-wc-modal-add-products"> 
  253. <div class="wc-backbone-modal"> 
  254. <div class="wc-backbone-modal-content"> 
  255. <section class="wc-backbone-modal-main" role="main"> 
  256. <header class="wc-backbone-modal-header"> 
  257. <h1><?php _e( 'Add products', 'woocommerce' ); ?></h1> 
  258. <button class="modal-close modal-close-link dashicons dashicons-no-alt"> 
  259. <span class="screen-reader-text">Close modal panel</span> 
  260. </button> 
  261. </header> 
  262. <article> 
  263. <form action="" method="post"> 
  264. <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="add_item_id" name="add_order_items[]" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>"></select> 
  265. </form> 
  266. </article> 
  267. <footer> 
  268. <div class="inner"> 
  269. <button id="btn-ok" class="button button-primary button-large"><?php _e( 'Add', 'woocommerce' ); ?></button> 
  270. </div> 
  271. </footer> 
  272. </section> 
  273. </div> 
  274. </div> 
  275. <div class="wc-backbone-modal-backdrop modal-close"></div> 
  276. </script> 
  277.  
  278. <script type="text/template" id="tmpl-wc-modal-add-tax"> 
  279. <div class="wc-backbone-modal"> 
  280. <div class="wc-backbone-modal-content"> 
  281. <section class="wc-backbone-modal-main" role="main"> 
  282. <header class="wc-backbone-modal-header"> 
  283. <h1><?php _e( 'Add tax', 'woocommerce' ); ?></h1> 
  284. <button class="modal-close modal-close-link dashicons dashicons-no-alt"> 
  285. <span class="screen-reader-text">Close modal panel</span> 
  286. </button> 
  287. </header> 
  288. <article> 
  289. <form action="" method="post"> 
  290. <table class="widefat"> 
  291. <thead> 
  292. <tr> 
  293. <th> </th> 
  294. <th><?php _e( 'Rate name', 'woocommerce' ); ?></th> 
  295. <th><?php _e( 'Tax class', 'woocommerce' ); ?></th> 
  296. <th><?php _e( 'Rate code', 'woocommerce' ); ?></th> 
  297. <th><?php _e( 'Rate %', 'woocommerce' ); ?></th> 
  298. </tr> 
  299. </thead> 
  300. <?php 
  301. $rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100" ); 
  302.  
  303. foreach ( $rates as $rate ) { 
  304. echo ' 
  305. <tr> 
  306. <td><input type="radio" id="add_order_tax_' . absint( $rate->tax_rate_id ) . '" name="add_order_tax" value="' . absint( $rate->tax_rate_id ) . '" /></td> 
  307. <td><label for="add_order_tax_' . absint( $rate->tax_rate_id ) . '">' . WC_Tax::get_rate_label( $rate ) . '</label></td> 
  308. <td>' . ( isset( $classes_options[ $rate->tax_rate_class ] ) ? $classes_options[ $rate->tax_rate_class ] : '-' ) . '</td> 
  309. <td>' . WC_Tax::get_rate_code( $rate ) . '</td> 
  310. <td>' . WC_Tax::get_rate_percent( $rate ) . '</td> 
  311. </tr> 
  312. '; 
  313. ?> 
  314. </table> 
  315. <?php if ( absint( $wpdb->get_var( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}woocommerce_tax_rates;" ) ) > 100 ) : ?> 
  316. <p> 
  317. <label for="manual_tax_rate_id"><?php _e( 'Or, enter tax rate ID:', 'woocommerce' ); ?></label><br/> 
  318. <input type="number" name="manual_tax_rate_id" id="manual_tax_rate_id" step="1" placeholder="<?php esc_attr_e( 'Optional', 'woocommerce' ); ?>" /> 
  319. </p> 
  320. <?php endif; ?> 
  321. </form> 
  322. </article> 
  323. <footer> 
  324. <div class="inner"> 
  325. <button id="btn-ok" class="button button-primary button-large"><?php _e( 'Add', 'woocommerce' ); ?></button> 
  326. </div> 
  327. </footer> 
  328. </section> 
  329. </div> 
  330. </div> 
  331. <div class="wc-backbone-modal-backdrop modal-close"></div> 
  332. </script> 
.