allow multiple taxes columns in order items
This commit is contained in:
parent
93cf3c88bd
commit
6176cb6b77
|
@ -20,12 +20,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
|
||||
<td class="tax_class" width="1%"></td>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<td class="quantity" width="1%">1</td>
|
||||
|
||||
<td class="line_cost" width="1%">
|
||||
|
@ -34,11 +28,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : for ( $i = 0; $i < count( $order_taxes ); $i++ ) : ?>
|
||||
|
||||
<td class="line_tax" width="1%"></td>
|
||||
<td class="line_tax" width="1%"></td>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php endfor; endif; ?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display: none;"></td>
|
||||
|
||||
<td class="wc-order-edit-line-item"></td>
|
||||
</tr>
|
||||
|
|
|
@ -29,22 +29,32 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</div>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
$line_tax_data = isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '';
|
||||
$tax_data = maybe_unserialize( $line_tax_data );
|
||||
|
||||
foreach ( $order_taxes as $tax_item ) :
|
||||
$tax_item_id = $tax_item['rate_id'];
|
||||
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
?>
|
||||
|
||||
<td class="line_tax" width="1%">
|
||||
<div class="view">
|
||||
<?php echo ( isset( $item['line_tax'] ) ) ? wc_price( wc_round_tax_total( $item['line_tax'] ) ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['line_tax'] ) ) ? esc_attr( wc_format_localized_price( $item['line_tax'] ) ) : ''; ?>" class="line_tax wc_input_price" />
|
||||
</div>
|
||||
</td>
|
||||
<td class="line_tax" width="1%">
|
||||
<div class="view">
|
||||
<?php echo ( '' != $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ) ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo absint( $tax_item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $tax_item_total ) ) ? esc_attr( wc_format_localized_price( $tax_item_total ) ) : ''; ?>" class="line_tax wc_input_price" />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display:none">
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display: none;">
|
||||
<input type="number" step="1" min="0" max="1" autocomplete="off" name="order_item_refund_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" size="4" class="quantity" />
|
||||
</td>
|
||||
|
||||
|
|
|
@ -177,11 +177,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<?php
|
||||
if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
$tax_data = maybe_unserialize( $item['line_tax_data'] );
|
||||
$line_tax_data = isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '';
|
||||
$tax_data = maybe_unserialize( $line_tax_data );
|
||||
|
||||
foreach ( $order_taxes as $tax_item ) :
|
||||
$tax_item_id = $tax_item['rate_id'];
|
||||
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
|
||||
$tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : '';
|
||||
|
||||
?>
|
||||
|
||||
<td class="line_tax" width="1%">
|
||||
|
|
|
@ -39,13 +39,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : for ( $i = 0; $i < count( $order_taxes ); $i++ ) : ?>
|
||||
|
||||
<td class="line_tax" width="1%"></td>
|
||||
<td class="line_tax" width="1%"></td>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php endfor; endif; ?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display:none"></td>
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display: none;"></td>
|
||||
|
||||
<td class="wc-order-edit-line-item">
|
||||
<div class="wc-order-edit-line-item-actions">
|
||||
|
|
|
@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<div class="view">
|
||||
<?php echo ! empty( $item['name'] ) ? esc_html( $item['name'] ) : __( 'Shipping', 'woocommerce' ); ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" placeholder="<?php _e( 'Shipping Name', 'woocommerce' ); ?>" name="shipping_method_title[<?php echo $item_id ? $item_id : 'new][]'; ?>]" value="<?php echo ( isset( $item['name'] ) ) ? esc_attr( $item['name'] ) : ''; ?>" />
|
||||
<select name="shipping_method[<?php echo $item_id ? $item_id : 'new][]'; ?>]">
|
||||
<optgroup label="<?php _e( 'Shipping Method', 'woocommerce' ); ?>">
|
||||
|
@ -49,24 +49,18 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<div class="view">
|
||||
<?php echo ( isset( $item['cost'] ) ) ? wc_price( wc_round_tax_total( $item['cost'] ) ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="shipping_cost[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['cost'] ) ) ? esc_attr( wc_format_localized_price( $item['cost'] ) ) : ''; ?>" class="line_total wc_input_price" /></label>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
for ( $i = 0; $i < count( $order_taxes ); $i++ ) :
|
||||
?>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : for ( $i = 0; $i < count( $order_taxes ); $i++ ) : ?>
|
||||
|
||||
<td class="line_tax" width="1%"></td>
|
||||
<td class="line_tax" width="1%"></td>
|
||||
|
||||
<?php
|
||||
endfor;
|
||||
endif;
|
||||
?>
|
||||
<?php endfor; endif; ?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display:none"></td>
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display: none;"></td>
|
||||
|
||||
<td class="wc-order-edit-line-item">
|
||||
<div class="wc-order-edit-line-item-actions">
|
||||
|
|
|
@ -243,15 +243,20 @@ function wc_save_order_items( $order_id, $items ) {
|
|||
|
||||
// Get values. Subtotals might not exist, in which case copy value from total field
|
||||
$line_total[ $item_id ] = isset( $line_total[ $item_id ] ) ? $line_total[ $item_id ] : 0;
|
||||
$line_tax[ $item_id ] = isset( $line_tax[ $item_id ] ) ? $line_tax[ $item_id ] : 0;
|
||||
$line_subtotal[ $item_id ] = isset( $line_subtotal[ $item_id ] ) ? $line_subtotal[ $item_id ] : $line_total[ $item_id ];
|
||||
$line_tax[ $item_id ] = isset( $line_tax[ $item_id ] ) ? $line_tax[ $item_id ] : array();
|
||||
$line_subtotal_tax[ $item_id ] = isset( $line_subtotal_tax[ $item_id ] ) ? $line_subtotal_tax[ $item_id ] : $line_tax[ $item_id ];
|
||||
|
||||
// Update values
|
||||
wc_update_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $line_subtotal[ $item_id ] ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $line_subtotal_tax[ $item_id ] ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_total', wc_format_decimal( $line_total[ $item_id ] ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax[ $item_id ] ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( array_sum( $line_subtotal_tax[ $item_id ] ) ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( array_sum( $line_tax[ $item_id ] ) ) );
|
||||
|
||||
// Save line tax data - Since 2.2
|
||||
$tax_data_total = array_map( 'wc_format_decimal', $line_tax[ $item_id ] );
|
||||
$tax_data_subtotal = array_map( 'wc_format_decimal', $line_subtotal_tax[ $item_id ] );
|
||||
wc_update_order_item_meta( $item_id, '_line_tax_data', array( 'total' => $tax_data_total, 'subtotal' => $tax_data_subtotal ) );
|
||||
|
||||
// Total up
|
||||
$subtotal += wc_format_decimal( $line_subtotal[ $item_id ] );
|
||||
|
|
Loading…
Reference in New Issue