created new methods to save and load the order items in shop_order screen
This commit is contained in:
parent
2f4b98d330
commit
d321395946
File diff suppressed because one or more lines are too long
|
@ -611,8 +611,11 @@ ul.wc_coupon_list_block {
|
|||
margin: 0;
|
||||
line-height: 2em;
|
||||
}
|
||||
.cancel-action {
|
||||
.cancel-action,
|
||||
.save-action,
|
||||
.calculate-action {
|
||||
float: left;
|
||||
margin-right: 2px;
|
||||
}
|
||||
}
|
||||
.wc-order-bulk-actions {
|
||||
|
@ -846,7 +849,7 @@ ul.wc_coupon_list_block {
|
|||
width: 2.5em;
|
||||
text-align: right;
|
||||
}
|
||||
.edit_order_item {
|
||||
.edit-order-item {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
margin: 0 .5em 0 0;
|
||||
|
@ -861,7 +864,7 @@ ul.wc_coupon_list_block {
|
|||
}
|
||||
}
|
||||
}
|
||||
.delete_order_item,
|
||||
.delete-order-item,
|
||||
.delete_refund {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
|
|
|
@ -21,6 +21,32 @@ jQuery( function ( $ ) {
|
|||
$( '#woocommerce-order-items' ).unblock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load order items
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function loadOrderItems() {
|
||||
var data = {
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
action: 'woocommerce_load_order_items',
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
$.ajax({
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$( '#woocommerce-order-items .inside' ).empty();
|
||||
$( '#woocommerce-order-items .inside' ).append( response );
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ORDERS
|
||||
$( '#woocommerce-order-actions input, #woocommerce-order-actions a' ).click( function () {
|
||||
window.onbeforeunload = '';
|
||||
|
@ -34,13 +60,13 @@ jQuery( function ( $ ) {
|
|||
});
|
||||
|
||||
// When the page is loaded, store the unit costs
|
||||
$('#order_items_list tr.item, #order_items_list tr.fee').each( function() {
|
||||
$(this).trigger('init_row');
|
||||
$(this).find('.edit').hide();
|
||||
} );
|
||||
$( '#order_items_list tr.item, #order_items_list tr.fee' ).each( function () {
|
||||
$( this ).trigger( 'init_row' );
|
||||
$( this ).find( '.edit' ).hide();
|
||||
});
|
||||
|
||||
$('#order_items_list')
|
||||
.on( 'init_row', 'tr.item', function() {
|
||||
$( 'body' )
|
||||
.on( 'init_row', '#order_items_list tr.item', function() {
|
||||
var $row = $(this);
|
||||
var $qty = $row.find('input.quantity');
|
||||
var qty = $qty.val();
|
||||
|
@ -65,7 +91,7 @@ jQuery( function ( $ ) {
|
|||
$row.attr( 'data-unit_total', unit_total );
|
||||
$row.attr( 'data-unit_total_tax', unit_total_tax );
|
||||
})
|
||||
.on( 'init_row', 'tr.fee', function() {
|
||||
.on( 'init_row', '#order_items_list tr.fee', function() {
|
||||
var $row = $(this);
|
||||
|
||||
var line_total = accounting.unformat( $row.find('input.line_total').val(), woocommerce_admin.mon_decimal_point );
|
||||
|
@ -77,13 +103,16 @@ jQuery( function ( $ ) {
|
|||
$row.attr( 'data-unit_total', unit_total );
|
||||
$row.attr( 'data-unit_total_tax', unit_total_tax );
|
||||
})
|
||||
.on( 'click', 'a.edit_order_item', function() {
|
||||
$(this).closest('tr').find('.view').hide();
|
||||
$(this).closest('tr').find('.edit').show();
|
||||
$(this).hide();
|
||||
.on( 'click', 'a.edit-order-item', function() {
|
||||
$( this ).closest( 'tr' ).find( '.view' ).hide();
|
||||
$( this ).closest( 'tr' ).find( '.edit' ).show();
|
||||
$( this ).hide();
|
||||
$( 'button.add-line-item' ).click();
|
||||
$( 'button.cancel-action' ).attr( 'data-reload', true );
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'a.delete_order_item', function () {
|
||||
.on( 'click', '#order_items_list a.delete-order-item', function () {
|
||||
var answer = window.confirm( woocommerce_admin_meta_boxes.remove_item_notice );
|
||||
|
||||
if ( answer ) {
|
||||
|
@ -110,7 +139,7 @@ jQuery( function ( $ ) {
|
|||
}
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.delete_refund', function () {
|
||||
.on( 'click', '#order_items_list .delete_refund', function () {
|
||||
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_delete_refund ) ) {
|
||||
var $refund = $( this ).closest( 'tr.refund' );
|
||||
var refund_id = $refund.attr( 'data-order_refund_id' );
|
||||
|
@ -128,15 +157,14 @@ jQuery( function ( $ ) {
|
|||
data: data,
|
||||
type: 'POST',
|
||||
success: function ( response ) {
|
||||
$refund.remove();
|
||||
window.location.reload();
|
||||
loadOrderItems();
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
})
|
||||
// When the qty is changed, increase or decrease costs
|
||||
.on( 'change', 'input.quantity', function() {
|
||||
.on( 'change', '#order_items_list input.quantity', function() {
|
||||
var $row = $(this).closest('tr.item');
|
||||
var qty = $(this).val();
|
||||
|
||||
|
@ -164,7 +192,7 @@ jQuery( function ( $ ) {
|
|||
$(this).trigger('quantity_changed');
|
||||
})
|
||||
// When subtotal is changed, update the unit costs
|
||||
.on( 'change', 'input.line_subtotal', function() {
|
||||
.on( 'change', '#order_items_list input.line_subtotal', function() {
|
||||
var $row = $(this).closest('tr.item');
|
||||
var $qty = $row.find('input.quantity');
|
||||
var qty = $qty.val();
|
||||
|
@ -173,7 +201,7 @@ jQuery( function ( $ ) {
|
|||
$row.attr( 'data-unit_subtotal', value );
|
||||
})
|
||||
// When total is changed, update the unit costs + discount amount
|
||||
.on( 'change', 'input.line_total', function() {
|
||||
.on( 'change', '#order_items_list input.line_total', function() {
|
||||
var $row = $(this).closest('tr.item');
|
||||
var $qty = $row.find('input.quantity');
|
||||
var qty = $qty.val();
|
||||
|
@ -182,7 +210,7 @@ jQuery( function ( $ ) {
|
|||
$row.attr( 'data-unit_total', value );
|
||||
})
|
||||
// When total is changed, update the unit costs + discount amount
|
||||
.on( 'change', 'input.line_subtotal_tax', function() {
|
||||
.on( 'change', '#order_items_list input.line_subtotal_tax', function() {
|
||||
var $row = $(this).closest('tr.item');
|
||||
var $qty = $row.find('input.quantity');
|
||||
var qty = $qty.val();
|
||||
|
@ -191,7 +219,7 @@ jQuery( function ( $ ) {
|
|||
$row.attr( 'data-unit_subtotal_tax', value );
|
||||
})
|
||||
// When total is changed, update the unit costs + discount amount
|
||||
.on( 'change', 'input.line_tax', function() {
|
||||
.on( 'change', '#order_items_list input.line_tax', function() {
|
||||
var $row = $(this).closest('tr.item');
|
||||
var $qty = $row.find('input.quantity');
|
||||
var qty = $qty.val();
|
||||
|
@ -199,7 +227,7 @@ jQuery( function ( $ ) {
|
|||
|
||||
$row.attr( 'data-unit_total_tax', value );
|
||||
})
|
||||
.on( 'change', '.wc-order-item-refund-quantity input', function() {
|
||||
.on( 'change', '#order_items_list .wc-order-item-refund-quantity input', function() {
|
||||
var refund_amount = 0;
|
||||
var $items = $('#order_items_list').find('tr.item, tr.fee');
|
||||
|
||||
|
@ -215,7 +243,7 @@ jQuery( function ( $ ) {
|
|||
$('#refund_amount').val( refund_amount ).change();
|
||||
})
|
||||
// Add some meta to a line item
|
||||
.on( 'click', 'button.add_order_item_meta', function () {
|
||||
.on( 'click', '#order_items_list button.add_order_item_meta', function () {
|
||||
|
||||
var $button = $( this );
|
||||
var $item = $button.closest( 'tr.item' );
|
||||
|
@ -241,7 +269,7 @@ jQuery( function ( $ ) {
|
|||
return false;
|
||||
})
|
||||
// Remove some meta from a line item
|
||||
.on('click', 'button.remove_order_item_meta', function(){
|
||||
.on('click', '#order_items_list button.remove_order_item_meta', function(){
|
||||
var answer = confirm( woocommerce_admin_meta_boxes.remove_item_meta )
|
||||
if ( answer ) {
|
||||
var $row = $(this).closest('tr');
|
||||
|
@ -268,13 +296,13 @@ jQuery( function ( $ ) {
|
|||
});
|
||||
|
||||
$( '#woocommerce-order-items' )
|
||||
.on( 'click', 'button.add_line_item', function () {
|
||||
.on( 'click', 'button.add-line-item', function () {
|
||||
$( 'div.wc-order-add-item' ).slideDown();
|
||||
$( 'div.wc-order-bulk-actions' ).slideUp();
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.refund_items', function () {
|
||||
.on( 'click', 'button.refund-items', function () {
|
||||
$( 'div.wc-order-refund-items' ).slideDown();
|
||||
$( 'div.wc-order-bulk-actions' ).slideUp();
|
||||
$( 'div.wc-order-totals-items' ).slideUp();
|
||||
|
@ -283,6 +311,33 @@ jQuery( function ( $ ) {
|
|||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.save-action', function () {
|
||||
var data = {
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
items: $( 'table.woocommerce_order_items :input[name]' ).serialize(),
|
||||
action: 'woocommerce_save_order_items',
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
$.ajax({
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$( '#woocommerce-order-items .inside' ).empty();
|
||||
$( '#woocommerce-order-items .inside' ).append( response );
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.calculate-action', function () {
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.cancel-action', function () {
|
||||
$( this ).closest( 'div.wc-order-data-row' ).slideUp();
|
||||
$( 'div.wc-order-bulk-actions' ).slideDown();
|
||||
|
@ -290,15 +345,20 @@ jQuery( function ( $ ) {
|
|||
$( '.wc-order-item-refund-quantity' ).hide();
|
||||
$( '.wc-order-edit-line-item' ).show();
|
||||
|
||||
// Reload the items
|
||||
if ( 'true' === $( this ).attr( 'data-reload' ) ) {
|
||||
loadOrderItems();
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add_order_item', function () {
|
||||
.on( 'click', 'button.add-order-item', function () {
|
||||
if ( window.WCBackbone.Modal.__instance === undefined ) {
|
||||
window.WCBackbone.Modal.__instance = new WCBackbone.Modal.View({ target: '#wc-modal-add-products' });
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add_order_fee', function () {
|
||||
.on( 'click', 'button.add-order-fee', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
|
@ -313,7 +373,7 @@ jQuery( function ( $ ) {
|
|||
});
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add_order_shipping', function () {
|
||||
.on( 'click', 'button.add-order-shipping', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
|
@ -447,8 +507,9 @@ jQuery( function ( $ ) {
|
|||
return false;
|
||||
});
|
||||
|
||||
$( '.wc-order-refund-items' )
|
||||
.on( 'change', '#refund_amount', function () {
|
||||
// Refund actions
|
||||
$( 'body' )
|
||||
.on( 'change', '.wc-order-refund-items #refund_amount', function () {
|
||||
$( 'button .wc-order-refund-amount .amount' ).text( accounting.formatMoney( $( this ).val(), {
|
||||
symbol: woocommerce_admin_meta_boxes.currency_format_symbol,
|
||||
decimal: woocommerce_admin_meta_boxes.currency_format_decimal_sep,
|
||||
|
@ -457,7 +518,7 @@ jQuery( function ( $ ) {
|
|||
format: woocommerce_admin_meta_boxes.currency_format
|
||||
} ) );
|
||||
})
|
||||
.on( 'click', 'button.do-api-refund, button.do-manual-refund', function () {
|
||||
.on( 'click', '.wc-order-refund-items button.do-api-refund, .wc-order-refund-items button.do-manual-refund', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_do_refund ) ) {
|
||||
|
@ -477,11 +538,11 @@ jQuery( function ( $ ) {
|
|||
api_refund: $( this ).is( '.do-api-refund' ),
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function ( response ) {
|
||||
if ( response === true ) {
|
||||
window.location.reload();
|
||||
loadOrderItems();
|
||||
} else if ( response.error ) {
|
||||
alert( response.error );
|
||||
window.alert( response.error );
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
|
@ -590,7 +651,7 @@ jQuery( function ( $ ) {
|
|||
$items.each( function() {
|
||||
var $row = $(this);
|
||||
var item_id = $row.find('input.order_item_id').val();
|
||||
$row.find('.edit_order_item').click();
|
||||
$row.find('.edit-order-item').click();
|
||||
|
||||
if ( response['item_taxes'][ item_id ] ) {
|
||||
$row.find('input.line_tax').val( response['item_taxes'][ item_id ]['line_tax'] ).change();
|
||||
|
@ -698,7 +759,7 @@ jQuery( function ( $ ) {
|
|||
});
|
||||
|
||||
$( 'select#add_item_id' ).trigger( 'chosen:updated' );
|
||||
$( 'table.woocommerce_order_items' ).unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
|
||||
$( '#order_items_list tr.new_row' ).trigger( 'init_row' ).removeClass( 'new_row' );
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -26,316 +26,14 @@ class WC_Meta_Box_Order_Items {
|
|||
|
||||
$order = $theorder;
|
||||
$data = get_post_meta( $post->ID );
|
||||
?>
|
||||
<div class="woocommerce_order_items_wrapper">
|
||||
<table cellpadding="0" cellspacing="0" class="woocommerce_order_items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" class="check-column" /></th>
|
||||
<th class="item" colspan="2"><?php _e( 'Item', 'woocommerce' ); ?></th>
|
||||
|
||||
<?php do_action( 'woocommerce_admin_order_item_headers' ); ?>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
<th class="tax_class"><?php _e( 'Tax Class', 'woocommerce' ); ?></th>
|
||||
<?php endif; ?>
|
||||
|
||||
<th class="quantity"><?php _e( 'Qty', 'woocommerce' ); ?></th>
|
||||
|
||||
<th class="line_cost"><?php _e( 'Total', 'woocommerce' ); ?></th>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
<th class="line_tax"><?php _e( 'Tax', 'woocommerce' ); ?></th>
|
||||
<?php endif; ?>
|
||||
|
||||
<th class="wc-order-item-refund-quantity" style="display:none"><?php _e( 'Refund', 'woocommerce' ); ?></th>
|
||||
|
||||
<th class="wc-order-edit-line-item" width="1%"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="order_items_list">
|
||||
|
||||
<?php
|
||||
// List order items
|
||||
$order_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', array( 'line_item', 'fee', 'shipping', 'coupon' ) ) );
|
||||
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
|
||||
|
||||
foreach ( $order_items as $item_id => $item ) {
|
||||
|
||||
switch ( $item['type'] ) {
|
||||
case 'line_item' :
|
||||
$_product = $order->get_product_from_item( $item );
|
||||
$item_meta = $order->get_item_meta( $item_id );
|
||||
|
||||
include( 'views/html-order-item.php' );
|
||||
break;
|
||||
case 'fee' :
|
||||
include( 'views/html-order-fee.php' );
|
||||
break;
|
||||
case 'shipping' :
|
||||
include( 'views/html-order-shipping.php' );
|
||||
break;
|
||||
case 'coupon' :
|
||||
include( 'views/html-order-coupon.php' );
|
||||
break;
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_order_item_' . $item['type'] . '_html', $item_id, $item );
|
||||
}
|
||||
|
||||
if ( $refunds = $order->get_refunds() ) {
|
||||
foreach ( $refunds as $refund ) {
|
||||
include( 'views/html-order-refund.php' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-totals wc-order-totals-items">
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Shipping', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_shipping() ); ?></span>
|
||||
</li>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Taxes', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_tax() ); ?></span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Order Discount', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_discount() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</span>
|
||||
<span class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Order Total', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total() ); ?></span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-bulk-actions">
|
||||
<p class="bulk_actions">
|
||||
<select>
|
||||
<option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
|
||||
<optgroup label="<?php _e( 'Edit', 'woocommerce' ); ?>">
|
||||
<option value="delete"><?php _e( 'Delete line item(s)', 'woocommerce' ); ?></option>
|
||||
</optgroup>
|
||||
<optgroup label="<?php _e( 'Stock Actions', 'woocommerce' ); ?>">
|
||||
<option value="reduce_stock"><?php _e( 'Reduce line item stock', 'woocommerce' ); ?></option>
|
||||
<option value="increase_stock"><?php _e( 'Increase line item stock', 'woocommerce' ); ?></option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
<button type="button" class="button do_bulk_action wc-reload" title="<?php _e( 'Apply', 'woocommerce' ); ?>"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button>
|
||||
</p>
|
||||
<p class="add_items">
|
||||
<button type="button" class="button add_line_item"><?php _e( 'Add line item(s)', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button refund_items"><?php _e( 'Refund', 'woocommerce' ); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-add-item" style="display:none;">
|
||||
<button type="button" class="button add_order_item"><?php _e( 'Add product(s)', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button add_order_fee"><?php _e( 'Add fee', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button add_order_shipping"><?php _e( 'Add shipping cost', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button cancel-action"><?php _e( 'Done', 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-totals wc-order-refund-items" style="display:none;">
|
||||
<ul>
|
||||
<li>
|
||||
<label for="restock_refunded_items"><?php _e( 'Restock refunded items', 'woocommerce' ); ?>:</label>
|
||||
<span class="checkbox"><input type="checkbox" id="restock_refunded_items" name="restock_refunded_items" checked="checked" /></span>
|
||||
</li>
|
||||
<li>
|
||||
<label><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</label>
|
||||
<span class="total">-<?php echo wc_price( $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<label><?php _e( 'Total available to refund', 'woocommerce' ); ?>:</label>
|
||||
<span class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label>
|
||||
<input type="text" class="text" id="refund_amount" name="refund_amount" class="wc_input_price" />
|
||||
</li>
|
||||
<li>
|
||||
<label for="refund_reason"><?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label>
|
||||
<input type="text" class="text" id="refund_reason" name="refund_reason" />
|
||||
</li>
|
||||
</ul>
|
||||
<button type="button" class="button button-primary do-api-refund"><?php printf( _x( 'Refund %s via %s', 'Refund $amount', 'woocommerce' ), '<span class="wc-order-refund-amount">' . wc_price( 0 ) . '</span>', $order->payment_method_title ); ?></button>
|
||||
<button type="button" class="button button-primary do-manual-refund"><?php _e( 'Refund manually', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
|
||||
<script type="text/template" id="wc-modal-add-products">
|
||||
<div class="wc-backbone-modal">
|
||||
<div class="wc-backbone-modal-content">
|
||||
<section class="wc-backbone-modal-main" role="main">
|
||||
<header>
|
||||
<h1><?php echo __( 'Add products', 'woocommerce' ); ?></h1>
|
||||
</header>
|
||||
<article>
|
||||
<form>
|
||||
<select id="add_item_id" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>" style="width: 96%"></select>
|
||||
</form>
|
||||
</article>
|
||||
<footer>
|
||||
<div class="inner">
|
||||
<button id="btn-cancel" class="button button-large"><?php echo __( 'Cancel' , 'woocommerce' ); ?></button>
|
||||
<button id="btn-ok" class="button button-primary button-large"><?php echo __( 'Add' , 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wc-backbone-modal-backdrop"> </div>
|
||||
</script>
|
||||
<?php
|
||||
include( 'views/html-order-items.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
global $wpdb;
|
||||
|
||||
// Order items + fees
|
||||
$subtotal = 0;
|
||||
$total = 0;
|
||||
|
||||
if ( isset( $_POST['order_item_id'] ) ) {
|
||||
|
||||
$get_values = array( 'order_item_id', 'order_item_name', 'order_item_qty', 'line_subtotal', 'line_subtotal_tax', 'line_total', 'line_tax', 'order_item_tax_class' );
|
||||
|
||||
foreach ( $get_values as $value ) {
|
||||
$$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array();
|
||||
}
|
||||
|
||||
foreach ( $order_item_id as $item_id ) {
|
||||
|
||||
$item_id = absint( $item_id );
|
||||
|
||||
if ( isset( $order_item_name[ $item_id ] ) ) {
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_items',
|
||||
array( 'order_item_name' => wc_clean( $order_item_name[ $item_id ] ) ),
|
||||
array( 'order_item_id' => $item_id ),
|
||||
array( '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $order_item_qty[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, '_qty', wc_stock_amount( $order_item_qty[ $item_id ] ) );
|
||||
}
|
||||
|
||||
if ( isset( $order_item_tax_class[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, '_tax_class', wc_clean( $order_item_tax_class[ $item_id ] ) );
|
||||
}
|
||||
|
||||
// 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_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 ] ) );
|
||||
|
||||
// Total up
|
||||
$subtotal += wc_format_decimal( $line_subtotal[ $item_id ] );
|
||||
$total += wc_format_decimal( $line_total[ $item_id ] );
|
||||
|
||||
// Clear meta cache
|
||||
wp_cache_delete( $item_id, 'order_item_meta' );
|
||||
}
|
||||
}
|
||||
|
||||
// Save meta
|
||||
$meta_keys = isset( $_POST['meta_key'] ) ? $_POST['meta_key'] : array();
|
||||
$meta_values = isset( $_POST['meta_value'] ) ? $_POST['meta_value'] : array();
|
||||
|
||||
foreach ( $meta_keys as $id => $meta_key ) {
|
||||
$meta_value = ( empty( $meta_values[ $id ] ) && ! is_numeric( $meta_values[ $id ] ) ) ? '' : $meta_values[ $id ];
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_itemmeta',
|
||||
array(
|
||||
'meta_key' => wp_unslash( $meta_key ),
|
||||
'meta_value' => wp_unslash( $meta_value )
|
||||
),
|
||||
array( 'meta_id' => $id ),
|
||||
array( '%s', '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
// Shipping Rows
|
||||
$order_shipping = 0;
|
||||
|
||||
if ( isset( $_POST['shipping_method_id'] ) ) {
|
||||
|
||||
$get_values = array( 'shipping_method_id', 'shipping_method_title', 'shipping_method', 'shipping_cost' );
|
||||
|
||||
foreach ( $get_values as $value ) {
|
||||
$$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array();
|
||||
}
|
||||
|
||||
foreach ( $shipping_method_id as $item_id => $value ) {
|
||||
|
||||
if ( 'new' == $item_id ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
$method_id = wc_clean( $shipping_method[ $item_id ][ $new_key ] );
|
||||
$method_title = wc_clean( $shipping_method_title[ $item_id ][ $new_key ] );
|
||||
$cost = wc_format_decimal( $shipping_cost[ $item_id ][ $new_key ] );
|
||||
|
||||
$new_id = wc_add_order_item( $post_id, array(
|
||||
'order_item_name' => $method_title,
|
||||
'order_item_type' => 'shipping'
|
||||
) );
|
||||
|
||||
if ( $new_id ) {
|
||||
wc_add_order_item_meta( $new_id, 'method_id', $method_id );
|
||||
wc_add_order_item_meta( $new_id, 'cost', $cost );
|
||||
}
|
||||
|
||||
$order_shipping += $cost;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$item_id = absint( $item_id );
|
||||
$method_id = wc_clean( $shipping_method[ $item_id ] );
|
||||
$method_title = wc_clean( $shipping_method_title[ $item_id ] );
|
||||
$cost = wc_format_decimal( $shipping_cost[ $item_id ] );
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_items',
|
||||
array( 'order_item_name' => $method_title ),
|
||||
array( 'order_item_id' => $item_id ),
|
||||
array( '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
wc_update_order_item_meta( $item_id, 'method_id', $method_id );
|
||||
wc_update_order_item_meta( $item_id, 'cost', $cost );
|
||||
|
||||
$order_shipping += $cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $post_id, '_order_shipping', $order_shipping );
|
||||
|
||||
// Update cart discount from item totals
|
||||
update_post_meta( $post_id, '_cart_discount', $subtotal - $total );
|
||||
wc_save_order_items( $post_id, $_POST );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<td class="wc-order-edit-line-item">
|
||||
<div class="wc-order-edit-line-item-actions">
|
||||
<a class="edit_order_item" href="#"></a><a class="delete_order_item" href="#"></a>
|
||||
<a class="edit-order-item" href="#"></a><a class="delete-order-item" href="#"></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -235,7 +235,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<td class="wc-order-edit-line-item">
|
||||
<div class="wc-order-edit-line-item-actions">
|
||||
<a class="edit_order_item" href="#"></a><a class="delete_order_item" href="#"></a>
|
||||
<a class="edit-order-item" href="#"></a><a class="delete-order-item" href="#"></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
?>
|
||||
<div class="woocommerce_order_items_wrapper">
|
||||
<table cellpadding="0" cellspacing="0" class="woocommerce_order_items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" class="check-column" /></th>
|
||||
<th class="item" colspan="2"><?php _e( 'Item', 'woocommerce' ); ?></th>
|
||||
|
||||
<?php do_action( 'woocommerce_admin_order_item_headers' ); ?>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
<th class="tax_class"><?php _e( 'Tax Class', 'woocommerce' ); ?></th>
|
||||
<?php endif; ?>
|
||||
|
||||
<th class="quantity"><?php _e( 'Qty', 'woocommerce' ); ?></th>
|
||||
|
||||
<th class="line_cost"><?php _e( 'Total', 'woocommerce' ); ?></th>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
<th class="line_tax"><?php _e( 'Tax', 'woocommerce' ); ?></th>
|
||||
<?php endif; ?>
|
||||
|
||||
<th class="wc-order-item-refund-quantity" style="display:none"><?php _e( 'Refund', 'woocommerce' ); ?></th>
|
||||
|
||||
<th class="wc-order-edit-line-item" width="1%"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="order_items_list">
|
||||
|
||||
<?php
|
||||
// List order items
|
||||
$order_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', array( 'line_item', 'fee', 'shipping', 'coupon' ) ) );
|
||||
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
|
||||
|
||||
foreach ( $order_items as $item_id => $item ) {
|
||||
|
||||
switch ( $item['type'] ) {
|
||||
case 'line_item' :
|
||||
$_product = $order->get_product_from_item( $item );
|
||||
$item_meta = $order->get_item_meta( $item_id );
|
||||
|
||||
include( 'html-order-item.php' );
|
||||
break;
|
||||
case 'fee' :
|
||||
include( 'html-order-fee.php' );
|
||||
break;
|
||||
case 'shipping' :
|
||||
include( 'html-order-shipping.php' );
|
||||
break;
|
||||
case 'coupon' :
|
||||
include( 'html-order-coupon.php' );
|
||||
break;
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_order_item_' . $item['type'] . '_html', $item_id, $item );
|
||||
}
|
||||
|
||||
if ( $refunds = $order->get_refunds() ) {
|
||||
foreach ( $refunds as $refund ) {
|
||||
include( 'html-order-refund.php' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-totals wc-order-totals-items">
|
||||
<ul>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Shipping', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_shipping() ); ?></span>
|
||||
</li>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Taxes', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_tax() ); ?></span>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Order Discount', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total_discount() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</span>
|
||||
<span class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label"><?php _e( 'Order Total', 'woocommerce' ); ?>:</span>
|
||||
<span class="total"><?php echo wc_price( $order->get_total() ); ?></span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-bulk-actions">
|
||||
<p class="bulk_actions">
|
||||
<select>
|
||||
<option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
|
||||
<optgroup label="<?php _e( 'Edit', 'woocommerce' ); ?>">
|
||||
<option value="delete"><?php _e( 'Delete line item(s)', 'woocommerce' ); ?></option>
|
||||
</optgroup>
|
||||
<optgroup label="<?php _e( 'Stock Actions', 'woocommerce' ); ?>">
|
||||
<option value="reduce_stock"><?php _e( 'Reduce line item stock', 'woocommerce' ); ?></option>
|
||||
<option value="increase_stock"><?php _e( 'Increase line item stock', 'woocommerce' ); ?></option>
|
||||
</optgroup>
|
||||
</select>
|
||||
|
||||
<button type="button" class="button do_bulk_action wc-reload" title="<?php _e( 'Apply', 'woocommerce' ); ?>"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button>
|
||||
</p>
|
||||
<p class="add_items">
|
||||
<button type="button" class="button add-line-item"><?php _e( 'Add line item(s)', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button refund-items"><?php _e( 'Refund', 'woocommerce' ); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-add-item" style="display:none;">
|
||||
<button type="button" class="button add-order-item"><?php _e( 'Add product(s)', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button add-order-fee"><?php _e( 'Add fee', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button add-order-shipping"><?php _e( 'Add shipping cost', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button button-primary save-action"><?php _e( 'Save', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button button-primary calculate-action"><?php _e( 'Calculate Total and Save', 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-totals wc-order-refund-items" style="display:none;">
|
||||
<ul>
|
||||
<li>
|
||||
<label for="restock_refunded_items"><?php _e( 'Restock refunded items', 'woocommerce' ); ?>:</label>
|
||||
<span class="checkbox"><input type="checkbox" id="restock_refunded_items" name="restock_refunded_items" checked="checked" /></span>
|
||||
</li>
|
||||
<li>
|
||||
<label><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</label>
|
||||
<span class="total">-<?php echo wc_price( $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<label><?php _e( 'Total available to refund', 'woocommerce' ); ?>:</label>
|
||||
<span class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded() ); ?></span>
|
||||
</li>
|
||||
<li>
|
||||
<label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label>
|
||||
<input type="text" class="text" id="refund_amount" name="refund_amount" class="wc_input_price" />
|
||||
</li>
|
||||
<li>
|
||||
<label for="refund_reason"><?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label>
|
||||
<input type="text" class="text" id="refund_reason" name="refund_reason" />
|
||||
</li>
|
||||
</ul>
|
||||
<button type="button" class="button button-primary do-api-refund"><?php printf( _x( 'Refund %s via %s', 'Refund $amount', 'woocommerce' ), '<span class="wc-order-refund-amount">' . wc_price( 0 ) . '</span>', $order->payment_method_title ); ?></button>
|
||||
<button type="button" class="button button-primary do-manual-refund"><?php _e( 'Refund manually', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button cancel-action"><?php _e( 'Cancel', 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
|
||||
<script type="text/template" id="wc-modal-add-products">
|
||||
<div class="wc-backbone-modal">
|
||||
<div class="wc-backbone-modal-content">
|
||||
<section class="wc-backbone-modal-main" role="main">
|
||||
<header>
|
||||
<h1><?php echo __( 'Add products', 'woocommerce' ); ?></h1>
|
||||
</header>
|
||||
<article>
|
||||
<form>
|
||||
<select id="add_item_id" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>" style="width: 96%"></select>
|
||||
</form>
|
||||
</article>
|
||||
<footer>
|
||||
<div class="inner">
|
||||
<button id="btn-cancel" class="button button-large"><?php echo __( 'Cancel' , 'woocommerce' ); ?></button>
|
||||
<button id="btn-ok" class="button button-primary button-large"><?php echo __( 'Add' , 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wc-backbone-modal-backdrop"> </div>
|
||||
</script>
|
|
@ -70,7 +70,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<td class="wc-order-edit-line-item">
|
||||
<div class="wc-order-edit-line-item-actions">
|
||||
<a class="edit_order_item" href="#"></a><a class="delete_order_item" href="#"></a>
|
||||
<a class="edit-order-item" href="#"></a><a class="delete-order-item" href="#"></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -73,7 +73,7 @@ function wc_create_page( $slug, $option = '', $page_title = '', $page_content =
|
|||
if ( $page_found ) {
|
||||
if ( ! $option_value )
|
||||
update_option( $option, $page_found );
|
||||
|
||||
|
||||
return $page_found;
|
||||
}
|
||||
|
||||
|
@ -195,3 +195,150 @@ function woocommerce_compile_less_styles() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save order items
|
||||
*
|
||||
* @since 2.2
|
||||
* @param int $order_id Order ID
|
||||
* @param array $items Order items to save
|
||||
* @return void
|
||||
*/
|
||||
function wc_save_order_items( $order_id, $items ) {
|
||||
global $wpdb;
|
||||
|
||||
// Order items + fees
|
||||
$subtotal = 0;
|
||||
$total = 0;
|
||||
|
||||
if ( isset( $items['order_item_id'] ) ) {
|
||||
|
||||
$get_values = array( 'order_item_id', 'order_item_name', 'order_item_qty', 'line_subtotal', 'line_subtotal_tax', 'line_total', 'line_tax', 'order_item_tax_class' );
|
||||
|
||||
foreach ( $get_values as $value ) {
|
||||
$$value = isset( $items[ $value ] ) ? $items[ $value ] : array();
|
||||
}
|
||||
|
||||
foreach ( $order_item_id as $item_id ) {
|
||||
|
||||
$item_id = absint( $item_id );
|
||||
|
||||
if ( isset( $order_item_name[ $item_id ] ) ) {
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_items',
|
||||
array( 'order_item_name' => wc_clean( $order_item_name[ $item_id ] ) ),
|
||||
array( 'order_item_id' => $item_id ),
|
||||
array( '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $order_item_qty[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, '_qty', wc_stock_amount( $order_item_qty[ $item_id ] ) );
|
||||
}
|
||||
|
||||
if ( isset( $order_item_tax_class[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, '_tax_class', wc_clean( $order_item_tax_class[ $item_id ] ) );
|
||||
}
|
||||
|
||||
// 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_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 ] ) );
|
||||
|
||||
// Total up
|
||||
$subtotal += wc_format_decimal( $line_subtotal[ $item_id ] );
|
||||
$total += wc_format_decimal( $line_total[ $item_id ] );
|
||||
|
||||
// Clear meta cache
|
||||
wp_cache_delete( $item_id, 'order_item_meta' );
|
||||
}
|
||||
}
|
||||
|
||||
// Save meta
|
||||
$meta_keys = isset( $items['meta_key'] ) ? $items['meta_key'] : array();
|
||||
$meta_values = isset( $items['meta_value'] ) ? $items['meta_value'] : array();
|
||||
|
||||
foreach ( $meta_keys as $id => $meta_key ) {
|
||||
$meta_value = ( empty( $meta_values[ $id ] ) && ! is_numeric( $meta_values[ $id ] ) ) ? '' : $meta_values[ $id ];
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_itemmeta',
|
||||
array(
|
||||
'meta_key' => wp_unslash( $meta_key ),
|
||||
'meta_value' => wp_unslash( $meta_value )
|
||||
),
|
||||
array( 'meta_id' => $id ),
|
||||
array( '%s', '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
}
|
||||
|
||||
// Shipping Rows
|
||||
$order_shipping = 0;
|
||||
|
||||
if ( isset( $items['shipping_method_id'] ) ) {
|
||||
|
||||
$get_values = array( 'shipping_method_id', 'shipping_method_title', 'shipping_method', 'shipping_cost' );
|
||||
|
||||
foreach ( $get_values as $value ) {
|
||||
$$value = isset( $items[ $value ] ) ? $items[ $value ] : array();
|
||||
}
|
||||
|
||||
foreach ( $shipping_method_id as $item_id => $value ) {
|
||||
|
||||
if ( 'new' == $item_id ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
$method_id = wc_clean( $shipping_method[ $item_id ][ $new_key ] );
|
||||
$method_title = wc_clean( $shipping_method_title[ $item_id ][ $new_key ] );
|
||||
$cost = wc_format_decimal( $shipping_cost[ $item_id ][ $new_key ] );
|
||||
|
||||
$new_id = wc_add_order_item( $order_id, array(
|
||||
'order_item_name' => $method_title,
|
||||
'order_item_type' => 'shipping'
|
||||
) );
|
||||
|
||||
if ( $new_id ) {
|
||||
wc_add_order_item_meta( $new_id, 'method_id', $method_id );
|
||||
wc_add_order_item_meta( $new_id, 'cost', $cost );
|
||||
}
|
||||
|
||||
$order_shipping += $cost;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$item_id = absint( $item_id );
|
||||
$method_id = wc_clean( $shipping_method[ $item_id ] );
|
||||
$method_title = wc_clean( $shipping_method_title[ $item_id ] );
|
||||
$cost = wc_format_decimal( $shipping_cost[ $item_id ] );
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_order_items',
|
||||
array( 'order_item_name' => $method_title ),
|
||||
array( 'order_item_id' => $item_id ),
|
||||
array( '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
wc_update_order_item_meta( $item_id, 'method_id', $method_id );
|
||||
wc_update_order_item_meta( $item_id, 'cost', $cost );
|
||||
|
||||
$order_shipping += $cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update order shipping total
|
||||
update_post_meta( $order_id, '_order_shipping', $order_shipping );
|
||||
|
||||
// Update cart discount from item totals
|
||||
update_post_meta( $order_id, '_cart_discount', $subtotal - $total );
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ class WC_AJAX {
|
|||
'add_order_item_meta' => false,
|
||||
'remove_order_item_meta' => false,
|
||||
'calc_line_taxes' => false,
|
||||
'save_order_items' => false,
|
||||
'load_order_items' => false,
|
||||
'add_order_note' => false,
|
||||
'delete_order_note' => false,
|
||||
'json_search_products' => false,
|
||||
|
@ -1307,6 +1309,44 @@ class WC_AJAX {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Save order items via ajax
|
||||
*/
|
||||
public static function save_order_items() {
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
if ( isset( $_POST['order_id'] ) && isset( $_POST['items'] ) ) {
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
|
||||
// Parse the jQuery serialized items
|
||||
$items = array();
|
||||
parse_str( $_POST['items'], $items );
|
||||
|
||||
// Save order items
|
||||
wc_save_order_items( $order_id, $items );
|
||||
|
||||
// Return HTML items
|
||||
$order = new WC_Order( $order_id );
|
||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load order items via ajax
|
||||
*/
|
||||
public static function load_order_items() {
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
// Return HTML items
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order note via ajax
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue