Merge pull request #5867 from claudiosmweb/new-order-items
New order items and refunds interface
This commit is contained in:
commit
3b71920d1c
File diff suppressed because one or more lines are too long
|
@ -611,9 +611,6 @@ ul.wc_coupon_list_block {
|
|||
margin: 0;
|
||||
line-height: 2em;
|
||||
}
|
||||
.cancel-action {
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
.wc-order-bulk-actions {
|
||||
background: #fefefe;
|
||||
|
@ -622,12 +619,14 @@ ul.wc_coupon_list_block {
|
|||
select {
|
||||
vertical-align: top;
|
||||
}
|
||||
p.bulk_actions {
|
||||
p.bulk-actions {
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
.wc-order-add-item {
|
||||
background: #fff;
|
||||
vertical-align: top;
|
||||
border-top: none;
|
||||
.add_item_id, .chosen-container {
|
||||
vertical-align: top;
|
||||
.search-field input {
|
||||
|
@ -638,13 +637,45 @@ ul.wc_coupon_list_block {
|
|||
width: 400px !important;
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
.wc-order-refund-items {
|
||||
ul {
|
||||
margin: 0 0 12px;
|
||||
padding-bottom: 5px;
|
||||
border-bottom: 1px solid #DFDFDF;
|
||||
.cancel-action,
|
||||
.save-action,
|
||||
.calculate-action {
|
||||
float: left;
|
||||
margin-right: 2px;
|
||||
}
|
||||
}
|
||||
.wc-order-totals {
|
||||
float: right;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
.amount {
|
||||
font-weight: bold;
|
||||
}
|
||||
.label {
|
||||
vertical-align: top;
|
||||
}
|
||||
.total {
|
||||
font-size: 1em !important;
|
||||
width: 10em;
|
||||
margin: 0 0 0 .5em;
|
||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
||||
box-sizing: border-box; /* Opera/IE 8+ */
|
||||
|
||||
input[type="text"] {
|
||||
width: 96%;
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
.refunded-total {
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
.refund-actions {
|
||||
margin-top: 5px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid #DFDFDF;
|
||||
|
||||
.button {
|
||||
float: right;
|
||||
margin-left: 4px;
|
||||
|
@ -653,25 +684,9 @@ ul.wc_coupon_list_block {
|
|||
float: left;
|
||||
margin-left: 0;
|
||||
}
|
||||
.amount {
|
||||
font-weight: bold;
|
||||
}
|
||||
label {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
input.text, .total, .checkbox {
|
||||
font-size: 1em !important;
|
||||
width: 10em;
|
||||
display: inline-block;
|
||||
margin: 0 0 0 .5em;
|
||||
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
|
||||
-moz-box-sizing: border-box; /* Firefox, other Gecko */
|
||||
box-sizing: border-box; /* Opera/IE 8+ */
|
||||
}
|
||||
}
|
||||
.add_meta {
|
||||
margin-left:0 !important;
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
h3 small {
|
||||
color: #999;
|
||||
|
@ -751,6 +766,9 @@ ul.wc_coupon_list_block {
|
|||
font-size: 1em;
|
||||
}
|
||||
}
|
||||
th.line_tax {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.quantity {
|
||||
text-align: center;
|
||||
input {
|
||||
|
@ -830,26 +848,7 @@ ul.wc_coupon_list_block {
|
|||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAARklEQVQYGWP8//8/AzGACV3Rnj17/oMwujiGQnQFMD7RChlBbsRmFcwkEO3i4sJImonIumGmg0xBFifaRKIVgj2DbAUuNgCfThpracSKqwAAAABJRU5ErkJggg==) no-repeat center;
|
||||
}
|
||||
}
|
||||
.wc-order-edit-line-item-actions {
|
||||
width: 2.5em;
|
||||
text-align: right;
|
||||
}
|
||||
.edit_order_item {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
margin: 0 .5em 0 0;
|
||||
&:before {
|
||||
.icon;
|
||||
content: "\e603";
|
||||
color: #999;
|
||||
}
|
||||
&:hover {
|
||||
&:before {
|
||||
color: #555;
|
||||
}
|
||||
}
|
||||
}
|
||||
.delete_order_item {
|
||||
.delete-order-tax {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
|
@ -867,6 +866,50 @@ ul.wc_coupon_list_block {
|
|||
}
|
||||
}
|
||||
|
||||
.wc-order-items-editable {
|
||||
.edit-order-item {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
margin: 0 .5em 0 0;
|
||||
&:before {
|
||||
.icon;
|
||||
content: "\e603";
|
||||
color: #999;
|
||||
}
|
||||
&:hover {
|
||||
&:before {
|
||||
color: #555;
|
||||
}
|
||||
}
|
||||
}
|
||||
.delete-order-item,
|
||||
.delete_refund {
|
||||
.ir;
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
&:before {
|
||||
.icon;
|
||||
content: "\e013";
|
||||
color: #999;
|
||||
}
|
||||
&:hover {
|
||||
&:before {
|
||||
color: @red;
|
||||
}
|
||||
}
|
||||
}
|
||||
.wc-order-edit-line-item-actions {
|
||||
width: 2.5em;
|
||||
text-align: right;
|
||||
}
|
||||
.wc-order-totals .wc-order-edit-line-item-actions {
|
||||
width: 1.5em;
|
||||
}
|
||||
.wc-order-totals .edit-order-item {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
#woocommerce-order-downloads {
|
||||
.buttons {
|
||||
float:left;
|
||||
|
@ -904,204 +947,6 @@ ul.wc_coupon_list_block {
|
|||
}
|
||||
}
|
||||
}
|
||||
#poststuff #woocommerce-order-totals {
|
||||
.inside {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
h4 {
|
||||
margin:0 !important;
|
||||
a.add_tax_row, a.add_total_row {
|
||||
display: inline-block;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.inline_total {
|
||||
float: right;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
.totals_group {
|
||||
border-top: 1px solid white;
|
||||
border-bottom: 1px solid #DDD;
|
||||
padding: 10px 12px 0 12px;
|
||||
&:first-child {
|
||||
border-top:0;
|
||||
}
|
||||
input, select {
|
||||
width: 100%;
|
||||
vertical-align: top;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
line-height: 1em;
|
||||
}
|
||||
select {
|
||||
height: 30px !important;
|
||||
}
|
||||
input {
|
||||
padding: 4px 6px;
|
||||
}
|
||||
::-webkit-input-placeholder { line-height: 1.4em; }
|
||||
::-moz-placeholder { line-height: 1.4em; } /* firefox 19+ */
|
||||
:-ms-input-placeholder { line-height: 1.4em; } /* ie */
|
||||
input:-moz-placeholder { line-height: 1.4em; }
|
||||
#_order_total, #_order_discount {
|
||||
margin: 6px 0 10px;
|
||||
}
|
||||
}
|
||||
.buttons {
|
||||
border-top: 1px solid white;
|
||||
padding: 1em 10px 1em 10px;
|
||||
margin: 0;
|
||||
text-align: right;
|
||||
.calc_line_taxes {
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
ul.totals {
|
||||
margin: 6px 0 0;
|
||||
float: left;
|
||||
li {
|
||||
float: left;
|
||||
clear: both;
|
||||
width: 100%;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
line-height: 1.2em;
|
||||
margin: 0;
|
||||
padding: 0 0 10px;
|
||||
label {
|
||||
font-weight: normal;
|
||||
display: block;
|
||||
font-size: 0.8em;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
li.left {
|
||||
float: left;
|
||||
width: 49%;
|
||||
clear: left;
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
li.right {
|
||||
float: right;
|
||||
width: 49%;
|
||||
clear: none;
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
li.wide {
|
||||
float: left;
|
||||
width: 100%;
|
||||
clear: left;
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.calculated {
|
||||
border-color: #ae8ca2;
|
||||
border-style: dotted;
|
||||
}
|
||||
}
|
||||
.total_rows {
|
||||
margin: 6px 0 0;
|
||||
.total_row:first-child {
|
||||
border-top:1px solid #dfdfdf;
|
||||
}
|
||||
.total_row:last-child {
|
||||
margin-bottom:9px;
|
||||
}
|
||||
}
|
||||
.total_row {
|
||||
margin:0 -12px;
|
||||
border-bottom:1px solid #DFDFDF;
|
||||
background: #fff;
|
||||
padding: 12px 12px 3px 12px;
|
||||
background:#f8f8f8;
|
||||
position: relative;
|
||||
p {
|
||||
margin:0 0 9px;
|
||||
}
|
||||
label {
|
||||
color:#999;
|
||||
display: block;
|
||||
margin: 0 0 3px;
|
||||
}
|
||||
p.first {
|
||||
float: left;
|
||||
width: 49%;
|
||||
clear: left;
|
||||
input, select {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
p.last {
|
||||
float: right;
|
||||
width: 49%;
|
||||
clear: none;
|
||||
input, select {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
p.wide {
|
||||
clear: both;
|
||||
input, select {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
a.delete_tax_row, a.delete_total_row, a.delete_refund {
|
||||
.ir;
|
||||
display:none;
|
||||
position: absolute;
|
||||
top:-.5em;
|
||||
right:-.5em;
|
||||
font-size:1.4em;
|
||||
&:before {
|
||||
.icon( "\e013" );
|
||||
color:white;
|
||||
background-color: #000;
|
||||
-webkit-border-radius:100%;
|
||||
border-radius:100%;
|
||||
box-shadow:0 1px 2px rgba(0,0,0,0.2);
|
||||
}
|
||||
&:hover:before {
|
||||
background-color: @red;
|
||||
}
|
||||
}
|
||||
&:hover, &:focus {
|
||||
a.delete_tax_row, a.delete_total_row, a.delete_refund {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
.refunds {
|
||||
margin: 6px 0 0;
|
||||
li.total_row {
|
||||
padding: 9px 12px 0;
|
||||
margin:0 -12px !important;
|
||||
&:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.amount {
|
||||
font-weight: bold;
|
||||
margin-right: 1em;
|
||||
float: left;
|
||||
}
|
||||
.date {
|
||||
float: right;
|
||||
color: #999;
|
||||
}
|
||||
p {
|
||||
clear: both;
|
||||
padding: 0 0 9px;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#poststuff #woocommerce-order-notes {
|
||||
.inside {
|
||||
margin:0;
|
||||
|
@ -3286,8 +3131,8 @@ table.bar_chart {
|
|||
----------------------------------*/
|
||||
.chosen-container-single .chosen-single {
|
||||
height: 26px;
|
||||
line-height: 26px;
|
||||
margin-top:1px;
|
||||
line-height: 26px;
|
||||
margin-top:1px;
|
||||
}
|
||||
.chosen-container-single .chosen-single div b {
|
||||
background: url('../images/chosen-sprite.png') no-repeat 0 4px !important;
|
||||
|
@ -3388,14 +3233,87 @@ table.bar_chart {
|
|||
}
|
||||
|
||||
#woocommerce-product-data .checkbox {
|
||||
width: 25px;
|
||||
width: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
@import 'chosen.less';
|
||||
|
||||
.chosen-container-single .chosen-single {
|
||||
abbr {
|
||||
top: 8px;
|
||||
}
|
||||
abbr {
|
||||
top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Backbone modal dialog
|
||||
----------------------------------*/
|
||||
.wc-backbone-modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 160000;
|
||||
|
||||
* {
|
||||
-webkit-box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.wc-backbone-modal-content {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
height: 300px;
|
||||
width: 400px;
|
||||
background: #fff;
|
||||
margin: -150px 0 0 -200px;
|
||||
}
|
||||
}
|
||||
|
||||
.wc-backbone-modal-backdrop {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
min-height: 360px;
|
||||
background: #000;
|
||||
opacity: .7;
|
||||
z-index: 159900;
|
||||
}
|
||||
|
||||
.wc-backbone-modal-main {
|
||||
header,
|
||||
article {
|
||||
display: block;
|
||||
position: relative;
|
||||
padding: 4px 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 200;
|
||||
line-height: 45px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 30px;
|
||||
z-index: 100;
|
||||
padding: 10px 0px;
|
||||
border: 0 solid #dfdfdf;
|
||||
border-width: 1px 0 0 0;
|
||||
box-shadow: 0 -4px 4px -4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
footer .inner {
|
||||
padding: 0 10px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,87 @@
|
|||
jQuery( function($){
|
||||
/*global woocommerce_admin_meta_boxes */
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
/**
|
||||
* Add order items loading block
|
||||
*/
|
||||
function addOrderItemsLoading() {
|
||||
$( '#woocommerce-order-items' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove order items loading block
|
||||
*/
|
||||
function removeOrderItemsLoading() {
|
||||
$( '#woocommerce-order-items' ).unblock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run TipTip
|
||||
*/
|
||||
function runTipTip() {
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
$( '.tips' ).tipTip({
|
||||
'attribute': 'data-tip',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
runTipTip();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ORDERS
|
||||
jQuery('#woocommerce-order-actions input, #woocommerce-order-actions a').click(function(){
|
||||
$( '#woocommerce-order-actions input, #woocommerce-order-actions a' ).click( function () {
|
||||
window.onbeforeunload = '';
|
||||
});
|
||||
|
||||
$('a.edit_address').click(function(event){
|
||||
$(this).hide();
|
||||
$(this).closest('.order_data_column').find('div.address').hide();
|
||||
$(this).closest('.order_data_column').find('div.edit_address').show();
|
||||
event.preventDefault();
|
||||
$( 'a.edit_address' ).click( function ( e ) {
|
||||
e.preventDefault();
|
||||
$( this ).hide();
|
||||
$( this ).closest( '.order_data_column' ).find( 'div.address' ).hide();
|
||||
$( this ).closest( '.order_data_column' ).find( 'div.edit_address' ).show();
|
||||
});
|
||||
|
||||
// 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();
|
||||
|
@ -44,7 +106,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 );
|
||||
|
@ -56,41 +118,68 @@ 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() {
|
||||
var answer = confirm( woocommerce_admin_meta_boxes.remove_item_notice );
|
||||
.on( 'click', '#order_items_list a.delete-order-item', function () {
|
||||
var answer = window.confirm( woocommerce_admin_meta_boxes.remove_item_notice );
|
||||
|
||||
if ( answer ) {
|
||||
var $item = $(this).closest('tr.item, tr.fee');
|
||||
var $item = $( this ).closest( 'tr.item, tr.fee, tr.shipping' );
|
||||
var order_item_id = $item.attr( 'data-order_item_id' );
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
order_item_ids: order_item_id,
|
||||
action: 'woocommerce_remove_order_item',
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
order_item_ids: order_item_id,
|
||||
action: 'woocommerce_remove_order_item',
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$.ajax({
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function ( response ) {
|
||||
$item.remove();
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
});
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.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' );
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_delete_refund',
|
||||
refund_id: refund_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function ( response ) {
|
||||
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();
|
||||
|
||||
|
@ -118,7 +207,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();
|
||||
|
@ -127,7 +216,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();
|
||||
|
@ -136,7 +225,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();
|
||||
|
@ -145,7 +234,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();
|
||||
|
@ -153,26 +242,42 @@ 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');
|
||||
var $items = $( '#order_items_list' ).find( 'tr.item, tr.fee, tr.shipping' );
|
||||
|
||||
$items.each(function() {
|
||||
var $row = $(this);
|
||||
$items.each( function () {
|
||||
var $row = $( this );
|
||||
var refund_qty = $row.find( '.wc-order-item-refund-quantity input' ).val();
|
||||
|
||||
if ( refund_qty ) {
|
||||
refund_amount = parseFloat( refund_amount ) + ( refund_qty * ( parseFloat( $row.attr( 'data-unit_total' ) ) + parseFloat( $row.attr( 'data-unit_total_tax' ) ) ) );
|
||||
}
|
||||
} );
|
||||
|
||||
$('#refund_amount').val( refund_amount ).change();
|
||||
if ( refund_qty ) {
|
||||
var unit_total = $( this ).find( 'input.line_total' ).val() || 0;
|
||||
unit_total = parseFloat( unit_total );
|
||||
|
||||
$( this ).find( 'input.line_tax' ).each( function () {
|
||||
var cost = $( this ).val() || 0;
|
||||
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
||||
unit_total = unit_total + parseFloat( cost );
|
||||
});
|
||||
|
||||
refund_amount = parseFloat( refund_amount ) + ( refund_qty * parseFloat( unit_total ) );
|
||||
}
|
||||
});
|
||||
|
||||
$( '#refund_amount' )
|
||||
.val( accounting.formatNumber(
|
||||
refund_amount,
|
||||
woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
||||
'',
|
||||
woocommerce_admin.mon_decimal_point
|
||||
) )
|
||||
.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');
|
||||
var $button = $( this );
|
||||
var $item = $button.closest( 'tr.item' );
|
||||
|
||||
var data = {
|
||||
order_item_id: $item.attr( 'data-order_item_id' ),
|
||||
|
@ -180,7 +285,7 @@ jQuery( function($){
|
|||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
$.ajax( {
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
|
@ -188,14 +293,14 @@ jQuery( function($){
|
|||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$item.find('tbody.meta_items').append( response );
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
|
||||
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');
|
||||
|
@ -206,7 +311,7 @@ jQuery( function($){
|
|||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
$.ajax( {
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
|
@ -214,98 +319,99 @@ jQuery( function($){
|
|||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$row.hide();
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
$( '#woocommerce-order-items' )
|
||||
.on( 'click', 'button.add-line-item', function () {
|
||||
$( 'div.wc-order-add-item' ).slideDown();
|
||||
$( 'div.wc-order-bulk-actions' ).slideUp();
|
||||
|
||||
$('#woocommerce-order-items')
|
||||
.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() {
|
||||
$('div.wc-order-refund-items').slideDown();
|
||||
$('div.wc-order-bulk-actions').slideUp();
|
||||
$('.wc-order-item-refund-quantity').show();
|
||||
$('.wc-order-edit-line-item').hide();
|
||||
.on( 'click', 'button.refund-items', function () {
|
||||
$( 'div.wc-order-refund-items' ).slideDown();
|
||||
$( 'div.wc-order-bulk-actions' ).slideUp();
|
||||
$( 'div.wc-order-totals-items' ).slideUp();
|
||||
$( '.wc-order-item-refund-quantity' ).show();
|
||||
$( '.wc-order-edit-line-item' ).hide();
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.cancel-action', function() {
|
||||
$(this).closest('div.wc-order-data-row').slideUp();
|
||||
$('div.wc-order-bulk-actions').slideDown();
|
||||
$('.wc-order-item-refund-quantity').hide();
|
||||
$('.wc-order-edit-line-item').show();
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add_order_item', function() {
|
||||
var add_item_ids = $('select#add_item_id').val();
|
||||
.on( 'click', '.cancel-action', function () {
|
||||
$( this ).closest( 'div.wc-order-data-row' ).slideUp();
|
||||
$( 'div.wc-order-bulk-actions' ).slideDown();
|
||||
$( 'div.wc-order-totals-items' ).slideDown();
|
||||
$( '.wc-order-item-refund-quantity' ).hide();
|
||||
$( '.wc-order-edit-line-item' ).show();
|
||||
|
||||
if ( add_item_ids ) {
|
||||
|
||||
count = add_item_ids.length;
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
$.each( add_item_ids, function( index, value ) {
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_item',
|
||||
item_to_add: value,
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
$('table.woocommerce_order_items tbody#order_items_list').append( response );
|
||||
|
||||
if (!--count) {
|
||||
$('select#add_item_id, #add_item_id_chosen .chosen-choices').css('border-color', '').val('');
|
||||
|
||||
runTipTip();
|
||||
|
||||
$('select#add_item_id').trigger("chosen:updated");
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
}
|
||||
|
||||
$('#order_items_list tr.new_row').trigger('init_row').removeClass('new_row');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
$('select#add_item_id, #add_item_id_chosen .chosen-choices').css('border-color', 'red');
|
||||
// Reload the items
|
||||
if ( 'true' === $( this ).attr( 'data-reload' ) ) {
|
||||
loadOrderItems();
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add_order_fee', function() {
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
.on( 'click', 'button.add-order-item', function () {
|
||||
$( this ).WCBackboneModal({
|
||||
template: '#wc-modal-add-products'
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add-order-fee', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_fee',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
action: 'woocommerce_add_order_fee',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$('table.woocommerce_order_items tbody#order_items_list').append( response );
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function ( response ) {
|
||||
$( 'table.woocommerce_order_items tbody#order_items_list' ).append( response );
|
||||
removeOrderItemsLoading();
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add-order-shipping', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_shipping',
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function ( response ) {
|
||||
$( 'table.woocommerce_order_items tbody#order_items_list' ).append( response );
|
||||
removeOrderItemsLoading();
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.add-order-tax', function () {
|
||||
$( this ).WCBackboneModal({
|
||||
template: '#wc-modal-add-tax'
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
// Bulk actions for line items
|
||||
.on( 'click', 'input.check-column', function() {
|
||||
if ( $(this).is(':checked') )
|
||||
if ( $(this).is(':checked') ) {
|
||||
$('#woocommerce-order-items').find('.check-column input').attr('checked', 'checked');
|
||||
else
|
||||
} else {
|
||||
$('#woocommerce-order-items').find('.check-column input').removeAttr('checked');
|
||||
}
|
||||
})
|
||||
.on( 'click', '.do_bulk_action', function() {
|
||||
var action = $(this).closest('.bulk_actions').find('select').val();
|
||||
var action = $(this).closest('.bulk-actions').find('select').val();
|
||||
var selected_rows = $('#woocommerce-order-items').find('.check-column input:checked');
|
||||
var item_ids = [];
|
||||
|
||||
|
@ -326,7 +432,7 @@ jQuery( function($){
|
|||
|
||||
if ( answer ) {
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
order_item_ids: item_ids,
|
||||
|
@ -342,14 +448,14 @@ jQuery( function($){
|
|||
$(selected_rows).each( function() {
|
||||
$(this).closest('tr.item, tr.fee').remove();
|
||||
} );
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
} else if ( action == 'reduce_stock' ) {
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
var quantities = {};
|
||||
|
||||
|
@ -375,13 +481,13 @@ jQuery( function($){
|
|||
type: 'POST',
|
||||
success: function( response ) {
|
||||
alert( response );
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
|
||||
} else if ( action == 'increase_stock' ) {
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
addOrderItemsLoading();
|
||||
|
||||
var quantities = {};
|
||||
|
||||
|
@ -407,33 +513,128 @@ jQuery( function($){
|
|||
type: 'POST',
|
||||
success: function( response ) {
|
||||
alert( response );
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.calculate-action', function () {
|
||||
if ( window.confirm( woocommerce_admin_meta_boxes.calc_totals ) ) {
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
// Get row totals
|
||||
var line_totals = 0;
|
||||
var tax = 0;
|
||||
var shipping = 0;
|
||||
var order_discount = $( '#_order_discount' ).val() || '0';
|
||||
|
||||
order_discount = accounting.unformat( order_discount.replace( ',', '.' ) );
|
||||
|
||||
$( '#order_items_list tr.shipping input.line_total' ).each( function () {
|
||||
cost = $( this ).val() || '0';
|
||||
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
||||
shipping = shipping + parseFloat( cost );
|
||||
});
|
||||
|
||||
$( '#order_items_list input.line_tax' ).each( function () {
|
||||
cost = $( this ).val() || '0';
|
||||
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
||||
tax = tax + parseFloat( cost );
|
||||
});
|
||||
|
||||
$( '#order_items_list tr.item, #order_items_list tr.fee' ).each( function () {
|
||||
line_total = $( this ).find( 'input.line_total' ).val() || '0';
|
||||
line_totals = line_totals + accounting.unformat( line_total.replace( ',', '.' ) );
|
||||
});
|
||||
|
||||
// Tax
|
||||
if ( 'yes' === woocommerce_admin_meta_boxes.round_at_subtotal ) {
|
||||
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||
}
|
||||
|
||||
// Set Total
|
||||
$( '#_order_total' )
|
||||
.val( accounting.formatNumber( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) )
|
||||
.change();
|
||||
|
||||
$( 'button.save-action' ).click();
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'button.save-action', function () {
|
||||
var data = {
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-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 );
|
||||
runTipTip();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', 'a.delete-order-tax', function () {
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_remote_order_tax',
|
||||
rate_id: $( this ).attr( 'data-rate_id' ),
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.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 );
|
||||
runTipTip();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.wc-order-refund-items')
|
||||
.on( 'change', '#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,
|
||||
thousand : woocommerce_admin_meta_boxes.currency_format_thousand_sep,
|
||||
precision : woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
||||
format : woocommerce_admin_meta_boxes.currency_format
|
||||
// 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,
|
||||
thousand: woocommerce_admin_meta_boxes.currency_format_thousand_sep,
|
||||
precision: woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
||||
format: woocommerce_admin_meta_boxes.currency_format
|
||||
} ) );
|
||||
})
|
||||
.on( 'click', 'button.do-api-refund, button.do-manual-refund', function() {
|
||||
$('#woocommerce-order-items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
.on( 'click', '.wc-order-refund-items button.do-api-refund, .wc-order-refund-items button.do-manual-refund', function () {
|
||||
addOrderItemsLoading();
|
||||
|
||||
if ( confirm( woocommerce_admin_meta_boxes.i18n_do_refund ) ) {
|
||||
var refund_amount = $('input#refund_amount').val();
|
||||
var refund_reason = $('input#refund_reason').val();
|
||||
var refund_qty = $.map( $('input[type=number][name^=order_item_refund_qty]' ), function( item ) {
|
||||
var result = [];
|
||||
result.push( $(item).closest('tr.item,tr.fee').data('order_item_id'), item.value );
|
||||
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_do_refund ) ) {
|
||||
var refund_amount = $( 'input#refund_amount' ).val();
|
||||
var refund_reason = $( 'input#refund_reason' ).val();
|
||||
var refund_qty = $.map( $( 'input[type=number][name^=order_item_refund_qty]' ), function( item ) {
|
||||
var result = [];
|
||||
result.push( $( item ).closest( 'tr.item,tr.fee' ).data( 'order_item_id' ), item.value );
|
||||
return result;
|
||||
});
|
||||
var data = {
|
||||
|
@ -442,49 +643,24 @@ jQuery( function($){
|
|||
refund_amount: refund_amount,
|
||||
refund_reason: refund_reason,
|
||||
refund_qty: JSON.stringify( refund_qty, null, '' ),
|
||||
api_refund: $(this).is('.do-api-refund'),
|
||||
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 ) {
|
||||
console.log( 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 );
|
||||
$('#woocommerce-order-items').unblock();
|
||||
window.alert( response.error );
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#woocommerce-order-items').unblock();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
});
|
||||
|
||||
// Display a total for taxes
|
||||
$('#woocommerce-order-totals')
|
||||
.on( 'change input', '.order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount', function() {
|
||||
var $this = $(this);
|
||||
var fields = $this.closest('.totals_group').find('input[type=number], .wc_input_price');
|
||||
var total = 0;
|
||||
|
||||
fields.each(function(){
|
||||
if ( $(this).val() )
|
||||
total = total + accounting.unformat( $(this).val(), woocommerce_admin.mon_decimal_point );
|
||||
});
|
||||
|
||||
if ( $this.is('.order_taxes_amount') || $this.is('.order_taxes_shipping_amount') ) {
|
||||
total = round( total, woocommerce_admin_meta_boxes.currency_format_num_decimals, woocommerce_admin_meta_boxes.tax_rounding_mode );
|
||||
}
|
||||
|
||||
var formatted_total = accounting.formatMoney( total, {
|
||||
symbol : woocommerce_admin_meta_boxes.currency_format_symbol,
|
||||
decimal : woocommerce_admin_meta_boxes.currency_format_decimal_sep,
|
||||
thousand : woocommerce_admin_meta_boxes.currency_format_thousand_sep,
|
||||
precision : woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
||||
format : woocommerce_admin_meta_boxes.currency_format
|
||||
} );
|
||||
|
||||
$this.closest('.totals_group').find('span.inline_total').text( formatted_total );
|
||||
})
|
||||
// Calculate totals
|
||||
.on('click', 'button.calc_line_taxes', function(){
|
||||
// Block write panel
|
||||
|
@ -559,7 +735,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();
|
||||
|
@ -580,68 +756,81 @@ jQuery( function($){
|
|||
$('.woocommerce_order_items_wrapper').unblock();
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.on('click', 'button.calc_totals', function(){
|
||||
// Block write panel
|
||||
$('#woocommerce-order-totals').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
});
|
||||
|
||||
var answer = confirm(woocommerce_admin_meta_boxes.calc_totals);
|
||||
// Adds new products in order items
|
||||
$( 'body' ).on( 'wc_backbone_modal_response', function ( e, target ) {
|
||||
if ( '#wc-modal-add-products' !== target ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (answer) {
|
||||
var add_item_ids = $( 'select#add_item_id' ).val();
|
||||
|
||||
// Get row totals
|
||||
var line_totals = 0;
|
||||
var tax = 0;
|
||||
var shipping = 0;
|
||||
var order_discount = $('#_order_discount').val() || '0';
|
||||
if ( add_item_ids ) {
|
||||
|
||||
order_discount = accounting.unformat( order_discount.replace(',', '.') );
|
||||
count = add_item_ids.length;
|
||||
|
||||
$('#shipping_rows').find('input[type=number], .wc_input_price').each(function(){
|
||||
cost = $(this).val() || '0';
|
||||
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
||||
shipping = shipping + parseFloat( cost );
|
||||
});
|
||||
addOrderItemsLoading();
|
||||
|
||||
$('#tax_rows').find('input[type=number], .wc_input_price').each(function(){
|
||||
cost = $(this).val() || '0';
|
||||
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
||||
tax = tax + parseFloat( cost );
|
||||
});
|
||||
$.each( add_item_ids, function ( index, value ) {
|
||||
|
||||
$('#order_items_list tr.item, #order_items_list tr.fee').each(function(){
|
||||
line_total = $(this).find('input.line_total').val() || '0';
|
||||
line_totals = line_totals + accounting.unformat( line_total.replace(',', '.') );
|
||||
});
|
||||
|
||||
// Tax
|
||||
if ( woocommerce_admin_meta_boxes.round_at_subtotal == 'yes' )
|
||||
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||
|
||||
// Set Total
|
||||
$('#_order_total').val( accounting.formatNumber( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) ).change();
|
||||
}
|
||||
|
||||
$('#woocommerce-order-totals').unblock();
|
||||
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.delete_refund', function () {
|
||||
if ( confirm( woocommerce_admin_meta_boxes.i18n_delete_refund ) ) {
|
||||
var $refund = $(this).closest('li');
|
||||
var data = {
|
||||
action: 'woocommerce_delete_refund',
|
||||
refund_id: $refund.data('id'),
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce,
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_item',
|
||||
item_to_add: value,
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$refund.remove();
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function ( response ) {
|
||||
|
||||
$( 'table.woocommerce_order_items tbody#order_items_list' ).append( response );
|
||||
|
||||
if ( !--count ) {
|
||||
$( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ).css( 'border-color', '' ).val( '' );
|
||||
runTipTip();
|
||||
$( 'select#add_item_id' ).trigger( 'chosen:updated' );
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
|
||||
$( '#order_items_list tr.new_row' ).trigger( 'init_row' ).removeClass( 'new_row' );
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
$( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ).css( 'border-color', 'red' );
|
||||
}
|
||||
});
|
||||
|
||||
// Adds new tax in order items
|
||||
$( 'body' ).on( 'wc_backbone_modal_response', function ( e, target ) {
|
||||
if ( '#wc-modal-add-tax' !== target ) {
|
||||
return;
|
||||
}
|
||||
|
||||
addOrderItemsLoading();
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_order_tax',
|
||||
rate_id: $( '#add-order-tax' ).val(),
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
$.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 );
|
||||
runTipTip();
|
||||
removeOrderItemsLoading();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('span.inline_total').closest('.totals_group').find('input').change();
|
||||
|
||||
// Download permissions
|
||||
|
@ -888,5 +1077,5 @@ jQuery( function($){
|
|||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
|||
jQuery( function($){
|
||||
|
||||
/*global woocommerce_admin_meta_boxes */
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
// run tip tip
|
||||
function runTipTip() {
|
||||
// remove any lingering tooltips
|
||||
|
@ -19,11 +20,11 @@ jQuery( function($){
|
|||
$('#titlediv #title').keyup(function( event ) {
|
||||
var code = event.keyCode || event.which;
|
||||
|
||||
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
|
||||
event.stopPropagation();
|
||||
$('#woocommerce-coupon-description').focus();
|
||||
return false;
|
||||
}
|
||||
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
|
||||
event.stopPropagation();
|
||||
$('#woocommerce-coupon-description').focus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$(function(){
|
||||
|
@ -56,61 +57,79 @@ jQuery( function($){
|
|||
|
||||
// Ajax Chosen Product Selectors
|
||||
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products',
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products',
|
||||
security: woocommerce_admin_meta_boxes.search_products_nonce
|
||||
}
|
||||
}
|
||||
}, function (data) {
|
||||
var terms = {};
|
||||
|
||||
$.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
$.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
|
||||
return terms;
|
||||
return terms;
|
||||
});
|
||||
|
||||
jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products_and_variations',
|
||||
security: woocommerce_admin_meta_boxes.search_products_nonce
|
||||
}
|
||||
}, function (data) {
|
||||
var terms = {};
|
||||
/**
|
||||
* Load Chosen for select products and variations
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function loadSelectProductAndVariation() {
|
||||
$( 'select.ajax_chosen_select_products_and_variations' ).ajaxChosen({
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products_and_variations',
|
||||
security: woocommerce_admin_meta_boxes.search_products_nonce
|
||||
}
|
||||
},
|
||||
function ( data ) {
|
||||
var terms = {};
|
||||
|
||||
$.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
$.each(data, function ( i, val ) {
|
||||
terms[i] = val;
|
||||
});
|
||||
|
||||
return terms;
|
||||
return terms;
|
||||
});
|
||||
}
|
||||
|
||||
// Run on document load
|
||||
loadSelectProductAndVariation();
|
||||
|
||||
// Load chosen inside WC Backbone Modal
|
||||
$( 'body' ).on( 'wc_backbone_modal_loaded', function ( e, target ) {
|
||||
if ( '#wc-modal-add-products' === target ) {
|
||||
loadSelectProductAndVariation();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_downloadable_products_and_variations',
|
||||
method: 'GET',
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_downloadable_products_and_variations',
|
||||
security: woocommerce_admin_meta_boxes.search_products_nonce
|
||||
}
|
||||
}
|
||||
}, function (data) {
|
||||
|
||||
var terms = {};
|
||||
|
||||
$.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
$.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
|
||||
return terms;
|
||||
return terms;
|
||||
});
|
||||
|
||||
$( ".date-picker" ).datepicker({
|
||||
|
@ -147,4 +166,4 @@ jQuery( function($){
|
|||
jQuery(this).find('.wc-metabox-content').hide();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}b(),a("#titlediv #title").keyup(function(b){var c=b.keyCode||b.which;return"9"==c&&a("#woocommerce-coupon-description").size()>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(function(){jQuery(".wc-metabox > h3").click(function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")})}),a("ul.wc-tabs").show(),a("div.panel-wrap").each(function(){a(this).find("div.panel:not(:first)").hide()}),a("ul.wc-tabs a").click(function(){var b=a(this).closest("div.panel-wrap");return a("ul.wc-tabs li",b).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",b).hide(),a(a(this).attr("href")).show(),!1}),a("ul.wc-tabs li:visible").eq(0).find("a").click(),jQuery("select.chosen_select").chosen(),jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"}),jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_downloadable_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0}),a(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0}),jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option").length||jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show(),!1}).on("click",".close_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide(),!1}),jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()})});
|
||||
jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}function c(){a("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c})}b(),a("#titlediv #title").keyup(function(b){var c=b.keyCode||b.which;return"9"==c&&a("#woocommerce-coupon-description").size()>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(function(){jQuery(".wc-metabox > h3").click(function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")})}),a("ul.wc-tabs").show(),a("div.panel-wrap").each(function(){a(this).find("div.panel:not(:first)").hide()}),a("ul.wc-tabs a").click(function(){var b=a(this).closest("div.panel-wrap");return a("ul.wc-tabs li",b).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",b).hide(),a(a(this).attr("href")).show(),!1}),a("ul.wc-tabs li:visible").eq(0).find("a").click(),jQuery("select.chosen_select").chosen(),jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"}),jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),c(),a("body").on("wc_backbone_modal_loaded",function(a,b){"#wc-modal-add-products"===b&&c()}),jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_downloadable_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(b){var c={};return a.each(b,function(a,b){c[a]=b}),c}),a(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0}),a(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0}),jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option").length||jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show(),!1}).on("click",".close_all",function(){return jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide(),!1}),jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()})});
|
|
@ -0,0 +1,99 @@
|
|||
/*global jQuery, Backbone, _ */
|
||||
( function ( $, Backbone, _ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WooCommerce Backbone Modal plugin
|
||||
*
|
||||
* @param {object} options
|
||||
*/
|
||||
$.fn.WCBackboneModal = function( options ) {
|
||||
return this.each( function () {
|
||||
( new $.WCBackboneModal( $( this ), options ) );
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the Backbone Modal
|
||||
*
|
||||
* @param {object} element [description]
|
||||
* @param {object} options [description]
|
||||
*/
|
||||
$.WCBackboneModal = function( element, options ) {
|
||||
// Set settings
|
||||
var settings = $.extend( {}, $.WCBackboneModal.defaultOptions, options );
|
||||
|
||||
if ( settings.template ) {
|
||||
new $.WCBackboneModal.View({
|
||||
target: settings.template
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set default options
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
$.WCBackboneModal.defaultOptions = {
|
||||
template: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the Backbone Modal
|
||||
*
|
||||
* @return {null}
|
||||
*/
|
||||
$.WCBackboneModal.View = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
id: 'wc-backbone-modal-dialog',
|
||||
_target: undefined,
|
||||
events: {
|
||||
'click #btn-cancel': 'closeButton',
|
||||
'click #btn-ok': 'addButton',
|
||||
},
|
||||
initialize: function ( data ) {
|
||||
this._target = data.target;
|
||||
_.bindAll( this, 'render' );
|
||||
this.render();
|
||||
},
|
||||
render: function () {
|
||||
this.$el.attr( 'tabindex' , '0' ).append( $( this._target ).html() );
|
||||
|
||||
$( 'body' ).css({
|
||||
'overflow': 'hidden'
|
||||
}).append( this.$el );
|
||||
$( 'body' ).trigger( 'wc_backbone_modal_loaded', this._target );
|
||||
},
|
||||
closeButton: function ( e ) {
|
||||
e.preventDefault();
|
||||
this.undelegateEvents();
|
||||
$( document ).off( 'focusin' );
|
||||
$( 'body' ).css({
|
||||
'overflow': 'auto'
|
||||
});
|
||||
this.remove();
|
||||
$( 'body' ).trigger( 'wc_backbone_modal_removed', this._target );
|
||||
},
|
||||
addButton: function ( e ) {
|
||||
$( 'body' ).trigger( 'wc_backbone_modal_response', this._target, this.getFormData() );
|
||||
this.closeButton( e );
|
||||
},
|
||||
getFormData: function () {
|
||||
var data = {};
|
||||
|
||||
$.each( $( 'form', this.$el ).serializeArray(), function( index, item ) {
|
||||
if ( data.hasOwnProperty( item.name ) ) {
|
||||
data[ item.name ] = $.makeArray( data[ item.name ] );
|
||||
data[ item.name ].push( item.value );
|
||||
}
|
||||
else {
|
||||
data[ item.name ] = item.value;
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
||||
}( jQuery, Backbone, _ ));
|
|
@ -0,0 +1 @@
|
|||
!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template})},a.WCBackboneModal.defaultOptions={template:""},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,events:{"click #btn-cancel":"closeButton","click #btn-ok":"addButton"},initialize:function(a){this._target=a.target,c.bindAll(this,"render"),this.render()},render:function(){this.$el.attr("tabindex","0").append(a(this._target).html()),a("body").css({overflow:"hidden"}).append(this.$el),a("body").trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),this.undelegateEvents(),a(document).off("focusin"),a("body").css({overflow:"auto"}),this.remove(),a("body").trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a("body").trigger("wc_backbone_modal_response",this._target,this.getFormData()),this.closeButton(b)},getFormData:function(){var b={};return a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b}})}(jQuery,Backbone,_);
|
|
@ -87,7 +87,7 @@ abstract class WC_Abstract_Order {
|
|||
foreach( $address as $key => $value ) {
|
||||
update_post_meta( $this->id, "_{$type}_" . $key, $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a product line item to the order
|
||||
|
@ -103,34 +103,47 @@ abstract class WC_Abstract_Order {
|
|||
);
|
||||
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
$item_id = wc_add_order_item( $this->id, array(
|
||||
$item_id = wc_add_order_item( $this->id, array(
|
||||
'order_item_name' => $product->get_title(),
|
||||
'order_item_type' => 'line_item'
|
||||
) );
|
||||
) );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wc_add_order_item_meta( $item_id, '_qty', wc_stock_amount( $qty ) );
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', $product->get_tax_class() );
|
||||
wc_add_order_item_meta( $item_id, '_product_id', $product->id );
|
||||
wc_add_order_item_meta( $item_id, '_variation_id', isset( $product->variation_id ) ? $product->variation_id : 0 );
|
||||
|
||||
// Set line item totals, either passed in or from the product
|
||||
wc_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( isset( $args['totals']['subtotal'] ) ? $args['totals']['subtotal'] : $product->get_price_excluding_tax( $qty ) ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( isset( $args['totals']['total'] ) ? $args['totals']['total'] : $product->get_price_excluding_tax( $qty ) ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( isset( $args['totals']['subtotal_tax'] ) ? $args['totals']['subtotal_tax'] : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( isset( $args['totals']['tax'] ) ? $args['totals']['tax'] : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, '_qty', wc_stock_amount( $qty ) );
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', $product->get_tax_class() );
|
||||
wc_add_order_item_meta( $item_id, '_product_id', $product->id );
|
||||
wc_add_order_item_meta( $item_id, '_variation_id', isset( $product->variation_id ) ? $product->variation_id : 0 );
|
||||
|
||||
// Add variation meta
|
||||
foreach ( $args['variation'] as $key => $value ) {
|
||||
wc_add_order_item_meta( $item_id, str_replace( 'attribute_', '', $key ), $value );
|
||||
}
|
||||
// Set line item totals, either passed in or from the product
|
||||
wc_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( isset( $args['totals']['subtotal'] ) ? $args['totals']['subtotal'] : $product->get_price_excluding_tax( $qty ) ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( isset( $args['totals']['total'] ) ? $args['totals']['total'] : $product->get_price_excluding_tax( $qty ) ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( isset( $args['totals']['subtotal_tax'] ) ? $args['totals']['subtotal_tax'] : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( isset( $args['totals']['tax'] ) ? $args['totals']['tax'] : 0 ) );
|
||||
|
||||
// Backorders
|
||||
if ( $product->backorders_require_notification() && $product->is_on_backorder( $qty ) ) {
|
||||
wc_add_order_item_meta( $item_id, apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $qty - max( 0, $product->get_total_stock() ) );
|
||||
// Save tax data - Since 2.2
|
||||
if ( isset( $args['totals']['tax_data'] ) ) {
|
||||
$tax_data = array();
|
||||
$tax_data['total'] = array_map( 'wc_format_decimal', $args['totals']['tax_data']['total'] );
|
||||
$tax_data['subtotal'] = array_map( 'wc_format_decimal', $args['totals']['tax_data']['subtotal'] );
|
||||
|
||||
wc_add_order_item_meta( $item_id, '_line_tax_data', $tax_data );
|
||||
} else {
|
||||
wc_add_order_item_meta( $item_id, '_line_tax_data', array( 'total' => array(), 'subtotal' => array() ) );
|
||||
}
|
||||
|
||||
// Add variation meta
|
||||
if ( ! empty( $args['variation'] ) ) {
|
||||
foreach ( $args['variation'] as $key => $value ) {
|
||||
wc_add_order_item_meta( $item_id, str_replace( 'attribute_', '', $key ), $value );
|
||||
}
|
||||
}
|
||||
|
||||
// Backorders
|
||||
if ( $product->backorders_require_notification() && $product->is_on_backorder( $qty ) ) {
|
||||
wc_add_order_item_meta( $item_id, apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $qty - max( 0, $product->get_total_stock() ) );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_order_add_product', $this->id, $item_id, $product, $qty, $args );
|
||||
|
@ -148,13 +161,13 @@ abstract class WC_Abstract_Order {
|
|||
$item_id = wc_add_order_item( $this->id, array(
|
||||
'order_item_name' => $code,
|
||||
'order_item_type' => 'coupon'
|
||||
) );
|
||||
) );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wc_add_order_item_meta( $item_id, 'discount_amount', $discount_amount );
|
||||
wc_add_order_item_meta( $item_id, 'discount_amount', $discount_amount );
|
||||
|
||||
do_action( 'woocommerce_order_add_coupon', $this->id, $item_id, $code, $discount_amount );
|
||||
|
||||
|
@ -172,23 +185,23 @@ abstract class WC_Abstract_Order {
|
|||
if ( ! $code ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$item_id = wc_add_order_item( $this->id, array(
|
||||
'order_item_name' => $code,
|
||||
'order_item_type' => 'tax'
|
||||
) );
|
||||
) );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wc_add_order_item_meta( $item_id, 'rate_id', $tax_rate_id );
|
||||
wc_add_order_item_meta( $item_id, 'label', WC_Tax::get_rate_label( $tax_rate_id ) );
|
||||
wc_add_order_item_meta( $item_id, 'compound', WC_Tax::is_compound( $tax_rate_id ) ? 1 : 0 );
|
||||
wc_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( $tax_amount ) );
|
||||
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( $shipping_tax_amount ) );
|
||||
wc_add_order_item_meta( $item_id, 'rate_id', $tax_rate_id );
|
||||
wc_add_order_item_meta( $item_id, 'label', WC_Tax::get_rate_label( $tax_rate_id ) );
|
||||
wc_add_order_item_meta( $item_id, 'compound', WC_Tax::is_compound( $tax_rate_id ) ? 1 : 0 );
|
||||
wc_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( $tax_amount ) );
|
||||
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( $shipping_tax_amount ) );
|
||||
|
||||
do_action( 'woocommerce_order_add_tax', $this->id, $item_id, $tax_rate_id, $tax_amount, $shipping_tax_amount );
|
||||
do_action( 'woocommerce_order_add_tax', $this->id, $item_id, $tax_rate_id, $tax_amount, $shipping_tax_amount );
|
||||
|
||||
return $item_id;
|
||||
}
|
||||
|
@ -200,23 +213,27 @@ abstract class WC_Abstract_Order {
|
|||
*/
|
||||
public function add_shipping( $shipping_rate ) {
|
||||
$item_id = wc_add_order_item( $this->id, array(
|
||||
'order_item_name' => $shipping_rate->label,
|
||||
'order_item_type' => 'shipping'
|
||||
) );
|
||||
'order_item_name' => $shipping_rate->label,
|
||||
'order_item_type' => 'shipping'
|
||||
) );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
wc_add_order_item_meta( $item_id, 'method_id', $shipping_rate->id );
|
||||
wc_add_order_item_meta( $item_id, 'cost', wc_format_decimal( $shipping_rate->cost ) );
|
||||
wc_add_order_item_meta( $item_id, 'cost', wc_format_decimal( $shipping_rate->cost ) );
|
||||
|
||||
do_action( 'woocommerce_order_add_shipping', $this->id, $item_id, $shipping_rate );
|
||||
// Save shipping taxes - Since 2.2
|
||||
$taxes = array_map( 'wc_format_decimal', $shipping_rate->taxes );
|
||||
wc_add_order_item_meta( $item_id, 'taxes', $taxes );
|
||||
|
||||
// Update total
|
||||
$this->set_total( $this->order_shipping + wc_format_decimal( $shipping_rate->cost ), 'shipping' );
|
||||
do_action( 'woocommerce_order_add_shipping', $this->id, $item_id, $shipping_rate );
|
||||
|
||||
return $item_id;
|
||||
// Update total
|
||||
$this->set_total( $this->order_shipping + wc_format_decimal( $shipping_rate->cost ), 'shipping' );
|
||||
|
||||
return $item_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,21 +245,25 @@ abstract class WC_Abstract_Order {
|
|||
$item_id = wc_add_order_item( $this->id, array(
|
||||
'order_item_name' => $fee->name,
|
||||
'order_item_type' => 'fee'
|
||||
) );
|
||||
) );
|
||||
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $item_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $fee->taxable ) {
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
|
||||
} else {
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', '0' );
|
||||
}
|
||||
if ( $fee->taxable ) {
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
|
||||
} else {
|
||||
wc_add_order_item_meta( $item_id, '_tax_class', '0' );
|
||||
}
|
||||
|
||||
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $fee->amount ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $fee->amount ) );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $fee->tax ) );
|
||||
|
||||
// Save tax data - Since 2.2
|
||||
$tax_data = array_map( 'wc_format_decimal', $fee->tax_data );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax_data', array( 'total' => $tax_data ) );
|
||||
|
||||
do_action( 'woocommerce_order_add_fee', $this->id, $item_id, $fee );
|
||||
|
||||
return $item_id;
|
||||
|
@ -279,7 +300,7 @@ abstract class WC_Abstract_Order {
|
|||
* Calculate taxes for all line items and shipping, and store the totals and tax rows.
|
||||
*
|
||||
* Will use the base country unless customer addresses are set.
|
||||
*
|
||||
*
|
||||
* @return bool success or fail
|
||||
*/
|
||||
public function calculate_taxes() {
|
||||
|
@ -287,17 +308,17 @@ abstract class WC_Abstract_Order {
|
|||
$tax_total = 0;
|
||||
$taxes = array();
|
||||
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
|
||||
|
||||
|
||||
if ( 'base' === $tax_based_on ) {
|
||||
$default = get_option( 'woocommerce_default_country' );
|
||||
$postcode = '';
|
||||
$city = '';
|
||||
if ( strstr( $default, ':' ) ) {
|
||||
list( $country, $state ) = explode( ':', $default );
|
||||
} else {
|
||||
if ( strstr( $default, ':' ) ) {
|
||||
list( $country, $state ) = explode( ':', $default );
|
||||
} else {
|
||||
$country = $default;
|
||||
$state = '';
|
||||
}
|
||||
}
|
||||
} elseif ( 'billing' === $tax_based_on ) {
|
||||
$country = $this->billing_country;
|
||||
$state = $this->billing_state;
|
||||
|
@ -333,7 +354,7 @@ abstract class WC_Abstract_Order {
|
|||
$tax_total += $line_tax;
|
||||
|
||||
wc_update_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $line_subtotal_tax ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax ) );
|
||||
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax ) );
|
||||
|
||||
// Sum the item taxes
|
||||
foreach ( array_keys( $taxes + $line_taxes ) as $key ) {
|
||||
|
@ -380,7 +401,7 @@ abstract class WC_Abstract_Order {
|
|||
|
||||
/**
|
||||
* Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
|
||||
*
|
||||
*
|
||||
* @return $total calculated grand total
|
||||
*/
|
||||
public function calculate_totals() {
|
||||
|
@ -522,7 +543,7 @@ abstract class WC_Abstract_Order {
|
|||
|
||||
/**
|
||||
* Get transaction id for the order
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function get_transaction_id() {
|
||||
return get_post_meta( $this->id, '_transaction_id', true );
|
||||
|
@ -1708,10 +1729,10 @@ abstract class WC_Abstract_Order {
|
|||
public function update_status( $new_status, $note = '' ) {
|
||||
$old_status = $this->get_status();
|
||||
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
|
||||
|
||||
|
||||
// Only update if they differ
|
||||
if ( $this->id && $new_status !== $old_status ) {
|
||||
|
||||
|
||||
// Update the order
|
||||
wp_update_post( array( 'ID' => $this->id, 'post_status' => 'wc-' . $new_status ) );
|
||||
$this->post_status = 'wc-' . $new_status;
|
||||
|
@ -2099,4 +2120,4 @@ abstract class WC_Abstract_Order {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,7 @@ class WC_Admin_Assets {
|
|||
}
|
||||
if ( in_array( str_replace( 'edit-', '', $screen->id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
|
||||
wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
|
||||
wp_enqueue_script( 'wc-admin-order-meta-boxes-modal', WC()->plugin_url() . '/assets/js/admin/order-backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wc-admin-order-meta-boxes' ), WC_VERSION );
|
||||
}
|
||||
if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
|
||||
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
|
||||
|
|
|
@ -40,7 +40,6 @@ class WC_Admin_Meta_Boxes {
|
|||
* Save actions - sends out other emails. Last to show latest data.
|
||||
*/
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Items::save', 10, 2 );
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Totals::save', 20, 2 );
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Downloads::save', 30, 2 );
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40, 2 );
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Actions::save', 50, 2 );
|
||||
|
@ -107,7 +106,6 @@ class WC_Admin_Meta_Boxes {
|
|||
foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
|
||||
add_meta_box( 'woocommerce-order-data', __( 'Order Data', 'woocommerce' ), 'WC_Meta_Box_Order_Data::output', $type, 'normal', 'high' );
|
||||
add_meta_box( 'woocommerce-order-items', __( 'Order Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', $type, 'normal', 'high' );
|
||||
add_meta_box( 'woocommerce-order-totals', __( 'Order Totals', 'woocommerce' ), 'WC_Meta_Box_Order_Totals::output', $type, 'side', 'default' );
|
||||
add_meta_box( 'woocommerce-order-notes', __( 'Order Notes', 'woocommerce' ), 'WC_Meta_Box_Order_Notes::output', $type, 'side', 'default' );
|
||||
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable Product Permissions', 'woocommerce' ) . ' <span class="tips" data-tip="' . __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) . '">[?]</span>', 'WC_Meta_Box_Order_Downloads::output', $type, 'normal', 'default' );
|
||||
add_meta_box( 'woocommerce-order-actions', __( 'Order Actions', 'woocommerce' ), 'WC_Meta_Box_Order_Actions::output', $type, 'side', 'high' );
|
||||
|
@ -175,11 +173,11 @@ class WC_Admin_Meta_Boxes {
|
|||
if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check the nonce
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the post being saved == the $post_id to prevent triggering this call for other save_post events
|
||||
if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
|
||||
|
|
|
@ -20,195 +20,20 @@ class WC_Meta_Box_Order_Items {
|
|||
public static function output( $post ) {
|
||||
global $thepostid, $theorder;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
if ( ! is_object( $theorder ) ) {
|
||||
$theorder = get_order( $thepostid );
|
||||
}
|
||||
|
||||
$order = $theorder;
|
||||
?>
|
||||
<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>
|
||||
$data = get_post_meta( $post->ID );
|
||||
|
||||
<?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' ) ) );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_order_item_' . $item['type'] . '_html', $item_id, $item );
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</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;">
|
||||
<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: 400px"></select>
|
||||
<button type="button" class="button add_order_item"><?php _e( 'Add item(s)', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button add_order_fee"><?php _e( 'Add fee', 'woocommerce' ); ?></button>
|
||||
<button type="button" class="button cancel-action"><?php _e( 'Done', 'woocommerce' ); ?></button>
|
||||
</div>
|
||||
<div class="wc-order-data-row 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>
|
||||
<?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' )
|
||||
);
|
||||
}
|
||||
|
||||
// Update cart discount from item totals
|
||||
update_post_meta( $post_id, '_cart_discount', $subtotal - $total );
|
||||
wc_save_order_items( $post_id, $_POST );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,367 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Order Totals
|
||||
*
|
||||
* Functions for displaying the order totals meta box.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Meta Boxes
|
||||
* @version 2.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class WC_Meta_Box_Order_Totals {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output() {
|
||||
global $theorder, $wpdb, $post;
|
||||
|
||||
if ( ! is_object( $theorder ) )
|
||||
$theorder = get_order( $post->ID );
|
||||
|
||||
$order = $theorder;
|
||||
|
||||
$data = get_post_meta( $post->ID );
|
||||
?>
|
||||
<div class="totals_group">
|
||||
<h4><span class="tax_total_display inline_total"></span><?php _e( 'Shipping', 'woocommerce' ); ?></h4>
|
||||
|
||||
<div id="shipping_rows" class="total_rows">
|
||||
<?php
|
||||
if ( WC()->shipping() )
|
||||
$shipping_methods = WC()->shipping->load_shipping_methods();
|
||||
|
||||
foreach ( $order->get_shipping_methods() as $item_id => $item ) {
|
||||
$chosen_method = $item['method_id'];
|
||||
$shipping_title = $item['name'];
|
||||
$shipping_cost = $item['cost'];
|
||||
|
||||
include( 'views/html-order-shipping.php' );
|
||||
}
|
||||
|
||||
// Pre 2.1
|
||||
if ( isset( $data['_shipping_method'] ) ) {
|
||||
$item_id = '';
|
||||
$chosen_method = ! empty( $data['_shipping_method'][0] ) ? $data['_shipping_method'][0] : '';
|
||||
$shipping_title = ! empty( $data['_shipping_method_title'][0] ) ? $data['_shipping_method_title'][0] : '';
|
||||
$shipping_cost = ! empty( $data['_order_shipping'][0] ) ? $data['_order_shipping'][0] : '';
|
||||
|
||||
include( 'views/html-order-shipping.php' );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<h4><a href="#" class="add_total_row" data-row="<?php
|
||||
$item_id = '';
|
||||
$chosen_method = '';
|
||||
$shipping_cost = '';
|
||||
$shipping_title = __( 'Shipping', 'woocommerce' );
|
||||
ob_start();
|
||||
include( 'views/html-order-shipping.php' );
|
||||
echo esc_attr( ob_get_clean() );
|
||||
?>"><?php _e( '+ Add shipping cost', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'These are the shipping and handling costs for the order.', 'woocommerce' ); ?>">[?]</span></a></a></h4>
|
||||
<div class="clear"></div>
|
||||
|
||||
<?php do_action( 'woocommerce_admin_order_totals_after_shipping', $post->ID ) ?>
|
||||
</div>
|
||||
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
|
||||
<div class="totals_group tax_rows_group">
|
||||
<h4><span class="tax_total_display inline_total"></span><?php _e( 'Taxes', 'woocommerce' ); ?></h4>
|
||||
<div id="tax_rows" class="total_rows">
|
||||
<?php
|
||||
global $wpdb;
|
||||
|
||||
$rates = $wpdb->get_results( "SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name" );
|
||||
|
||||
$tax_codes = array();
|
||||
|
||||
foreach( $rates as $rate ) {
|
||||
$code = array();
|
||||
|
||||
$code[] = $rate->tax_rate_country;
|
||||
$code[] = $rate->tax_rate_state;
|
||||
$code[] = $rate->tax_rate_name ? sanitize_title( $rate->tax_rate_name ) : 'TAX';
|
||||
$code[] = absint( $rate->tax_rate_priority );
|
||||
|
||||
$tax_codes[ $rate->tax_rate_id ] = strtoupper( implode( '-', array_filter( $code ) ) );
|
||||
}
|
||||
|
||||
foreach ( $order->get_taxes() as $item_id => $item ) {
|
||||
include( 'views/html-order-tax.php' );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<h4><a href="#" class="add_total_row" data-row="<?php
|
||||
$item_id = '';
|
||||
$item = '';
|
||||
ob_start();
|
||||
include( 'views/html-order-tax.php' );
|
||||
echo esc_attr( ob_get_clean() );
|
||||
?>"><?php _e( '+ Add tax row', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'These rows contain taxes for this order. This allows you to display multiple or compound taxes rather than a single total.', 'woocommerce' ); ?>">[?]</span></a></a></h4>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="totals_group">
|
||||
<h4><label for="_order_discount"><?php _e( 'Order Discount', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'This is the total discount applied after tax.', 'woocommerce' ); ?>">[?]</span></label></h4>
|
||||
<input type="text" class="wc_input_price" id="_order_discount" name="_order_discount" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
|
||||
if ( isset( $data['_order_discount'][0] ) )
|
||||
echo esc_attr( wc_format_localized_price( $data['_order_discount'][0] ) );
|
||||
?>" />
|
||||
</div>
|
||||
<div class="totals_group">
|
||||
<h4><label for="_order_total"><?php _e( 'Order Total', 'woocommerce' ); ?></label></h4>
|
||||
<input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
|
||||
if ( isset( $data['_order_total'][0] ) )
|
||||
echo esc_attr( wc_format_localized_price( $data['_order_total'][0] ) );
|
||||
?>" />
|
||||
</div>
|
||||
<?php
|
||||
$coupons = $order->get_items( array( 'coupon' ) );
|
||||
|
||||
if ( $coupons ) {
|
||||
?>
|
||||
<div class="totals_group">
|
||||
<ul class="wc_coupon_list"><?php
|
||||
foreach ( $coupons as $item_id => $item ) {
|
||||
|
||||
$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['name'] ) );
|
||||
|
||||
$link = $post_id ? add_query_arg( array( 'post' => $post_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) : add_query_arg( array( 's' => $item['name'], 'post_status' => 'all', 'post_type' => 'shop_coupon' ), admin_url( 'edit.php' ) );
|
||||
|
||||
echo '<li class="tips code" data-tip="' . esc_attr( wc_price( $item['discount_amount'] ) ) . '"><a href="' . esc_url( $link ) . '"><span>' . esc_html( $item['name'] ). '</span></a></li>';
|
||||
}
|
||||
?></ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( $refunds = $order->get_refunds() ) {
|
||||
?>
|
||||
<div class="totals_group">
|
||||
<h4><?php _e( 'Refunds', 'woocommerce' ); ?></h4>
|
||||
<ul class="total_rows refunds"><?php
|
||||
foreach ( $refunds as $refund ) {
|
||||
echo '<li class="total_row" data-id="' . $refund->id . '">
|
||||
<p>' . wc_price( '-' . $refund->get_refund_amount() ) . ' <span class="date">' . date_i18n( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), strtotime( $refund->post_date ) ) . '</span></p>';
|
||||
|
||||
if ( $refund->get_refund_reason() ) {
|
||||
echo '<p> ' . esc_html( $refund->get_refund_reason() ) . '</p>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<a href="#" class="delete_refund">×</a>
|
||||
</li>';
|
||||
}
|
||||
?></ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<p class="buttons">
|
||||
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
|
||||
<button type="button" class="button calc_line_taxes"><?php _e( 'Calculate Tax', 'woocommerce' ); ?></button>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="button calc_totals"><?php _e( 'Calculate Total', 'woocommerce' ); ?></button>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
global $wpdb;
|
||||
|
||||
// Save tax rows
|
||||
$total_tax = 0;
|
||||
$total_shipping_tax = 0;
|
||||
|
||||
if ( isset( $_POST['order_taxes_id'] ) ) {
|
||||
|
||||
$get_values = array( 'order_taxes_id', 'order_taxes_rate_id', 'order_taxes_amount', 'order_taxes_shipping_amount' );
|
||||
|
||||
foreach( $get_values as $value )
|
||||
$$value = isset( $_POST[ $value ] ) ? $_POST[ $value ] : array();
|
||||
|
||||
foreach( $order_taxes_id as $item_id => $value ) {
|
||||
|
||||
if ( $item_id == 'new' ) {
|
||||
|
||||
foreach ( $value as $new_key => $new_value ) {
|
||||
$rate_id = absint( $order_taxes_rate_id[ $item_id ][ $new_key ] );
|
||||
|
||||
if ( $rate_id ) {
|
||||
$rate = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id ) );
|
||||
$label = $rate->tax_rate_name ? $rate->tax_rate_name : WC()->countries->tax_or_vat();
|
||||
$compound = $rate->tax_rate_compound ? 1 : 0;
|
||||
|
||||
$code = array();
|
||||
|
||||
$code[] = $rate->tax_rate_country;
|
||||
$code[] = $rate->tax_rate_state;
|
||||
$code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
|
||||
$code[] = absint( $rate->tax_rate_priority );
|
||||
$code = strtoupper( implode( '-', array_filter( $code ) ) );
|
||||
} else {
|
||||
$code = '';
|
||||
$label = WC()->countries->tax_or_vat();
|
||||
}
|
||||
|
||||
// Add line item
|
||||
$new_id = wc_add_order_item( $post_id, array(
|
||||
'order_item_name' => wc_clean( $code ),
|
||||
'order_item_type' => 'tax'
|
||||
) );
|
||||
|
||||
// Add line item meta
|
||||
if ( $new_id ) {
|
||||
wc_update_order_item_meta( $new_id, 'rate_id', $rate_id );
|
||||
wc_update_order_item_meta( $new_id, 'label', $label );
|
||||
wc_update_order_item_meta( $new_id, 'compound', $compound );
|
||||
|
||||
if ( isset( $order_taxes_amount[ $item_id ][ $new_key ] ) ) {
|
||||
wc_update_order_item_meta( $new_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] ) );
|
||||
|
||||
$total_tax += wc_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] );
|
||||
}
|
||||
|
||||
if ( isset( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) ) {
|
||||
wc_update_order_item_meta( $new_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) );
|
||||
|
||||
$total_shipping_tax += wc_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$item_id = absint( $item_id );
|
||||
$rate_id = absint( $order_taxes_rate_id[ $item_id ] );
|
||||
|
||||
if ( $rate_id ) {
|
||||
$rate = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id ) );
|
||||
$label = $rate->tax_rate_name ? $rate->tax_rate_name : WC()->countries->tax_or_vat();
|
||||
$compound = $rate->tax_rate_compound ? 1 : 0;
|
||||
|
||||
$code = array();
|
||||
|
||||
$code[] = $rate->tax_rate_country;
|
||||
$code[] = $rate->tax_rate_state;
|
||||
$code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
|
||||
$code[] = absint( $rate->tax_rate_priority );
|
||||
$code = strtoupper( implode( '-', array_filter( $code ) ) );
|
||||
} else {
|
||||
$code = '';
|
||||
$label = WC()->countries->tax_or_vat();
|
||||
}
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . "woocommerce_order_items",
|
||||
array( 'order_item_name' => wc_clean( $code ) ),
|
||||
array( 'order_item_id' => $item_id ),
|
||||
array( '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
wc_update_order_item_meta( $item_id, 'rate_id', $rate_id );
|
||||
wc_update_order_item_meta( $item_id, 'label', $label );
|
||||
wc_update_order_item_meta( $item_id, 'compound', $compound );
|
||||
|
||||
if ( isset( $order_taxes_amount[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ] ) );
|
||||
|
||||
$total_tax += wc_format_decimal( $order_taxes_amount[ $item_id ] );
|
||||
}
|
||||
|
||||
if ( isset( $order_taxes_shipping_amount[ $item_id ] ) ) {
|
||||
wc_update_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ] ) );
|
||||
|
||||
$total_shipping_tax += wc_format_decimal( $order_taxes_shipping_amount[ $item_id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update totals
|
||||
update_post_meta( $post_id, '_order_tax', wc_format_decimal( $total_tax ) );
|
||||
update_post_meta( $post_id, '_order_shipping_tax', wc_format_decimal( $total_shipping_tax ) );
|
||||
update_post_meta( $post_id, '_order_discount', wc_format_decimal( $_POST['_order_discount'] ) );
|
||||
update_post_meta( $post_id, '_order_total', wc_format_decimal( $_POST['_order_total'] ) );
|
||||
|
||||
// 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 ( $item_id == 'new' ) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete rows
|
||||
if ( isset( $_POST['delete_order_item_id'] ) ) {
|
||||
$delete_ids = $_POST['delete_order_item_id'];
|
||||
|
||||
foreach ( $delete_ids as $id )
|
||||
wc_delete_order_item( absint( $id ) );
|
||||
}
|
||||
|
||||
delete_post_meta( $post_id, '_shipping_method' );
|
||||
delete_post_meta( $post_id, '_shipping_method_title' );
|
||||
update_post_meta( $post_id, '_order_shipping', $order_shipping );
|
||||
add_post_meta( $post_id, '_order_currency', get_woocommerce_currency(), true );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
?>
|
||||
<tr class="coupon <?php echo ( ! empty( $class ) ) ? $class : ''; ?>" data-order_item_id="<?php echo $item_id; ?>">
|
||||
<td class="check-column"></td>
|
||||
|
||||
<td class="thumb"></td>
|
||||
|
||||
<td class="name">
|
||||
<div class="view">
|
||||
<?php
|
||||
$coupon_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['name'] ) );
|
||||
|
||||
$coupon_url = $coupon_id ? add_query_arg( array( 'post' => $coupon_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) : add_query_arg( array( 's' => $item['name'], 'post_status' => 'all', 'post_type' => 'shop_coupon' ), admin_url( 'edit.php' ) );
|
||||
|
||||
echo '<a href="' . esc_url( $coupon_url ) . '"><span>' . esc_html( $item['name'] ). '</span></a>';
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="quantity" width="1%">1</td>
|
||||
|
||||
<td class="line_cost" width="1%">
|
||||
<div class="view">
|
||||
<?php echo wc_price( $item['discount_amount'] ); ?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : for ( $i = 0; $i < count( $order_taxes ); $i++ ) : ?>
|
||||
|
||||
<td class="line_tax" width="1%"></td>
|
||||
|
||||
<?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>
|
|
@ -12,78 +12,55 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<div class="view">
|
||||
<?php echo ! empty( $item['name'] ) ? esc_html( $item['name'] ) : __( 'Fee', 'woocommerce' ); ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" placeholder="<?php _e( 'Fee Name', 'woocommerce' ); ?>" name="order_item_name[<?php echo absint( $item_id ); ?>]" value="<?php echo ( isset( $item['name'] ) ) ? esc_attr( $item['name'] ) : ''; ?>" />
|
||||
<input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
$classes_options[''] = __( 'Standard', 'woocommerce' );
|
||||
$tax_class = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : '';
|
||||
|
||||
if ( $tax_classes ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<td class="tax_class" width="1%">
|
||||
<div class="view">
|
||||
<?php
|
||||
$item_value = isset( $classes_options[ $tax_class ] ) ? esc_attr( $classes_options[ $tax_class ] ) : '';
|
||||
echo $item_value ? $item_value : __( 'Standard', 'woocommerce' );
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>">
|
||||
<option value="0" <?php selected( 0, $tax_class ) ?>><?php _e( 'N/A', 'woocommerce' ); ?></option>
|
||||
<optgroup label="<?php _e( 'Taxable', 'woocommerce' ); ?>">
|
||||
<?php
|
||||
foreach ( $classes_options as $value => $name ) {
|
||||
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $tax_class, false ) . '>'. esc_html( $name ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<td class="quantity" width="1%">1</td>
|
||||
|
||||
<td class="line_cost" width="1%">
|
||||
<div class="view">
|
||||
<?php echo ( isset( $item['line_total'] ) ) ? wc_price( wc_round_tax_total( $item['line_total'] ) ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['line_total'] ) ) ? esc_attr( wc_format_localized_price( $item['line_total'] ) ) : ''; ?>" class="line_total wc_input_price" /></label>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<?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 );
|
||||
|
||||
<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>
|
||||
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 endif; ?>
|
||||
?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display:none">
|
||||
<input type="number" step="<?php echo apply_filters( 'woocommerce_quantity_input_step', '1', $_product ); ?>" min="0" max="1" autocomplete="off" name="order_item_refund_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" size="4" class="quantity" />
|
||||
<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
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<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="refund-quantity" />
|
||||
</td>
|
||||
|
||||
<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>
|
||||
</tr>
|
||||
|
|
|
@ -3,7 +3,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
exit; // Exit if accessed directly
|
||||
}
|
||||
?>
|
||||
|
||||
<tr class="item <?php echo apply_filters( 'woocommerce_admin_html_order_item_class', ( ! empty( $class ) ? $class : '' ), $item ); ?>" data-order_item_id="<?php echo $item_id; ?>">
|
||||
<td class="check-column"><input type="checkbox" /></td>
|
||||
<td class="thumb">
|
||||
|
@ -96,7 +95,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<table class="meta" cellspacing="0">
|
||||
<tfoot>
|
||||
<tr>
|
||||
|
@ -148,42 +147,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<?php do_action( 'woocommerce_admin_order_item_values', $_product, $item, absint( $item_id ) ); ?>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('woocommerce_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
$classes_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( $tax_classes ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<td class="tax_class" width="1%">
|
||||
<div class="view">
|
||||
<?php
|
||||
$item_value = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : '';
|
||||
echo $classes_options[ $item_value ];
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<select class="tax_class" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" title="<?php _e( 'Tax class', 'woocommerce' ); ?>">
|
||||
<?php
|
||||
$item_value = isset( $item['tax_class'] ) ? sanitize_title( $item['tax_class'] ) : '';
|
||||
|
||||
foreach ( $classes_options as $value => $name )
|
||||
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $item_value, false ) . '>' . esc_html( $name ) . '</option>';
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
|
||||
<td class="quantity" width="1%">
|
||||
<div class="view">
|
||||
<?php echo ( isset( $item['qty'] ) ) ? esc_html( $item['qty'] ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="number" step="<?php echo 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['qty'] ); ?>" size="4" class="quantity" />
|
||||
</div>
|
||||
</td>
|
||||
|
@ -200,43 +168,56 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<div class="edit" style="display: none;">
|
||||
<span class="subtotal"><label><?php _e( 'Subtotal', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'Before pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_localized_price( $item['line_subtotal'] ) ) : ''; ?>" class="line_subtotal wc_input_price" /></label></span>
|
||||
|
||||
<label><?php _e( 'Total', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'After pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['line_total'] ) ) ? esc_attr( wc_format_localized_price( $item['line_total'] ) ) : ''; ?>" class="line_total wc_input_price" /></label>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<?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 );
|
||||
|
||||
<td class="line_tax" width="1%">
|
||||
<div class="view">
|
||||
<?php
|
||||
if ( isset( $item['line_tax'] ) ) {
|
||||
if ( isset( $item['line_subtotal_tax'] ) && $item['line_subtotal_tax'] != $item['line_tax'] ) {
|
||||
echo '<del>' . wc_price( wc_round_tax_total( $item['line_subtotal_tax'] ) ) . '</del> ';
|
||||
}
|
||||
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 ] : '';
|
||||
|
||||
echo wc_price( wc_round_tax_total( $item['line_tax'] ) );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display:none">
|
||||
<span class="subtotal"><input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $item['line_subtotal_tax'] ) ) ? esc_attr( wc_format_localized_price( $item['line_subtotal_tax'] ) ) : ''; ?>" class="line_subtotal_tax wc_input_price" /></span>
|
||||
?>
|
||||
|
||||
<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
|
||||
if ( '' != $tax_item_total ) {
|
||||
if ( isset( $tax_item_subtotal ) && $tax_item_subtotal != $tax_item_total ) {
|
||||
echo '<del>' . wc_price( wc_round_tax_total( $tax_item_subtotal ) ) . '</del> ';
|
||||
}
|
||||
|
||||
<?php endif; ?>
|
||||
echo wc_price( wc_round_tax_total( $tax_item_total ) );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="edit" style="display: none;">
|
||||
<span class="subtotal"><input type="text" name="line_subtotal_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_subtotal ) ) ? esc_attr( wc_format_localized_price( $tax_item_subtotal ) ) : ''; ?>" class="line_subtotal_tax wc_input_price" /></span>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display:none">
|
||||
<input type="number" step="<?php echo apply_filters( 'woocommerce_quantity_input_step', '1', $_product ); ?>" min="0" max="<?php echo esc_attr( $item['qty'] ); ?>" autocomplete="off" name="order_item_refund_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" size="4" class="quantity" />
|
||||
<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
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<td class="wc-order-item-refund-quantity" width="1%" style="display: none;">
|
||||
<input type="number" step="<?php echo apply_filters( 'woocommerce_quantity_input_step', '1', $_product ); ?>" min="0" max="<?php echo esc_attr( $item['qty'] ); ?>" autocomplete="off" name="order_item_refund_qty[<?php echo absint( $item_id ); ?>]" placeholder="0" size="4" class="refund-quantity" />
|
||||
</td>
|
||||
|
||||
<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>
|
||||
</tr>
|
||||
|
|
|
@ -0,0 +1,289 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) {
|
||||
$order_taxes = $order->get_taxes();
|
||||
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
|
||||
$classes_options = array();
|
||||
$classes_options[''] = __( 'Standard', 'woocommerce' );
|
||||
|
||||
if ( $tax_classes ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_options[ sanitize_title( $class ) ] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="woocommerce_order_items_wrapper wc-order-items-editable">
|
||||
<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' ); ?>
|
||||
|
||||
<th class="quantity"><?php _e( 'Qty', 'woocommerce' ); ?></th>
|
||||
|
||||
<th class="line_cost"><?php _e( 'Total', 'woocommerce' ); ?></th>
|
||||
|
||||
<?php
|
||||
if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) :
|
||||
foreach ( $order_taxes as $tax_id => $tax_item ) :
|
||||
$tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] );
|
||||
$tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' );
|
||||
?>
|
||||
|
||||
<th class="line_tax">
|
||||
<span><?php echo esc_attr( $tax_class_name ); ?> </span>
|
||||
<span class="tips" data-tip="<?php
|
||||
echo esc_attr( $tax_item['label'] . ' (' . $tax_item['name'] . ')' );
|
||||
?>">[?]</span>
|
||||
<input type="hidden" name="order_taxes[<?php echo $tax_id; ?>]" value="<?php echo esc_attr( $tax_item['rate_id'] ); ?>">
|
||||
<a class="delete-order-tax" href="#" data-rate_id="<?php echo $tax_id; ?>"></a>
|
||||
</th>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
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-items wc-order-items-editable">
|
||||
<table class="wc-order-totals">
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Shipping', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'This is the shipping and handling total costs for the order.', 'woocommerce' ); ?>">[?]</span>:</td>
|
||||
<td class="total"><?php echo wc_price( $order->get_total_shipping() ); ?></td>
|
||||
<td width="1%"></td>
|
||||
</tr>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Taxes', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'This is the total taxes for this order.', 'woocommerce' ); ?>">[?]</span>:</td>
|
||||
<td class="total"><?php echo wc_price( $order->get_total_tax() ); ?></td>
|
||||
<td width="1%"></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Order Discount', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'This is the total discount applied after tax.', 'woocommerce' ); ?>">[?]</span>:</td>
|
||||
<td class="total">
|
||||
<div class="view"><?php echo wc_price( $order->get_total_discount() ); ?></div>
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" class="wc_input_price" id="_order_discount" name="_order_discount" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $data['_order_discount'][0] ) ) ? esc_attr( wc_format_localized_price( $data['_order_discount'][0] ) ) : ''; ?>" />
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td><div class="wc-order-edit-line-item-actions"><a class="edit-order-item" href="#"></a></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</td>
|
||||
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded() ); ?></td>
|
||||
<td width="1%"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Order Total', 'woocommerce' ); ?>:</td>
|
||||
<td class="total">
|
||||
<div class="view"><?php echo wc_price( $order->get_total() ); ?></div>
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo ( isset( $data['_order_total'][0] ) ) ? esc_attr( wc_format_localized_price( $data['_order_total'][0] ) ) : ''; ?>" />
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td><div class="wc-order-edit-line-item-actions"><a class="edit-order-item" href="#"></a></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="clear"></div>
|
||||
</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>
|
||||
<button type="button" class="button button-primary calculate-action"><?php _e( 'Calculate Total', '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>
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
|
||||
<button type="button" class="button add-order-tax"><?php _e( 'Add Tax', 'woocommerce' ); ?></button>
|
||||
<?php endif; ?>
|
||||
<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>
|
||||
</div>
|
||||
<div class="wc-order-data-row wc-order-refund-items" style="display: none;">
|
||||
<table class="wc-order-totals">
|
||||
<tr>
|
||||
<td class="label"><label for="restock_refunded_items"><?php _e( 'Restock refunded items', 'woocommerce' ); ?>:</label></td>
|
||||
<td class="total"><input type="checkbox" id="restock_refunded_items" name="restock_refunded_items" checked="checked" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</td>
|
||||
<td class="total">-<?php echo wc_price( $order->get_total_refunded() ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><?php _e( 'Total available to refund', 'woocommerce' ); ?>:</td>
|
||||
<td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded() ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label></td>
|
||||
<td class="total">
|
||||
<input type="text" class="text" id="refund_amount" name="refund_amount" class="wc_input_price" />
|
||||
<div class="clear"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="refund_reason"><?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label></td>
|
||||
<td class="total">
|
||||
<input type="text" class="text" id="refund_reason" name="refund_reason" />
|
||||
<div class="clear"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="clear"></div>
|
||||
<div class="refund-actions">
|
||||
<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 class="clear"></div>
|
||||
</div>
|
||||
</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 action="" method="post">
|
||||
<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>
|
||||
|
||||
<script type="text/template" id="wc-modal-add-tax">
|
||||
<div class="wc-backbone-modal">
|
||||
<div class="wc-backbone-modal-content">
|
||||
<section class="wc-backbone-modal-main" role="main">
|
||||
<header>
|
||||
<h1><?php echo __( 'Add tax', 'woocommerce' ); ?></h1>
|
||||
</header>
|
||||
<article>
|
||||
<form action="" method="post">
|
||||
<select id="add-order-tax" name="add_order_tax" style="width: 96%;">
|
||||
<?php
|
||||
$rates = $wpdb->get_results( "SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority, tax_rate_class FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name" );
|
||||
|
||||
$tax_codes = array();
|
||||
|
||||
foreach ( $rates as $rate ) {
|
||||
$code = array();
|
||||
|
||||
$code[] = $rate->tax_rate_country;
|
||||
$code[] = $rate->tax_rate_state;
|
||||
$code[] = $rate->tax_rate_name ? sanitize_title( $rate->tax_rate_name ) : 'TAX';
|
||||
$code[] = absint( $rate->tax_rate_priority );
|
||||
|
||||
$tax_codes[ $rate->tax_rate_class ][ $rate->tax_rate_id ] = strtoupper( implode( '-', array_filter( $code ) ) );
|
||||
}
|
||||
|
||||
$tax_codes = array_reverse( $tax_codes );
|
||||
|
||||
foreach ( $tax_codes as $tax_class => $tax_values ) :
|
||||
?>
|
||||
<optgroup label="<?php echo isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax Rate', 'woocommerce' ); ?>">
|
||||
|
||||
<?php foreach ( $tax_values as $tax_id => $tax_code ) : ?>
|
||||
|
||||
<option value="<?php echo $tax_id; ?>"><?php echo esc_html( urldecode( $tax_code ) ); ?></option>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</optgroup>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</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>
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
?>
|
||||
<tr class="refund <?php echo ( ! empty( $class ) ) ? $class : ''; ?>" data-order_refund_id="<?php echo $refund->id; ?>">
|
||||
<td class="check-column"><input type="checkbox" /></td>
|
||||
|
||||
<td class="thumb"></td>
|
||||
|
||||
<td class="name">
|
||||
<?php _e( 'Refund', 'woocommerce' ); ?>
|
||||
<table class="display_meta" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><?php _e( 'Date', 'woocommerce' ); ?>:</th>
|
||||
<td>
|
||||
<p><?php echo date_i18n( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), strtotime( $refund->post_date ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ( ! empty( $refund->get_refund_reason() ) ) : ?>
|
||||
<tr>
|
||||
<th><?php _e( 'Reason', 'woocommerce' ); ?>:</th>
|
||||
<td>
|
||||
<p><?php echo esc_html( $refund->get_refund_reason() ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="hidden" class="order_refund_id" name="order_refund_id[]" value="<?php echo esc_attr( $refund->id ); ?>" />
|
||||
</td>
|
||||
|
||||
<td class="quantity" width="1%">1</td>
|
||||
|
||||
<td class="line_cost" width="1%">
|
||||
<div class="view">
|
||||
<?php echo wc_price( '-' . $refund->get_refund_amount() ); ?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : for ( $i = 0; $i < count( $order_taxes ); $i++ ) : ?>
|
||||
|
||||
<td class="line_tax" width="1%"></td>
|
||||
|
||||
<?php endfor; endif; ?>
|
||||
|
||||
<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">
|
||||
<a class="delete_refund" href="#"></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
|
@ -1,44 +1,91 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
?>
|
||||
<div class="total_row shipping_row" data-order_item_id="<?php echo $item_id; ?>">
|
||||
<p class="wide">
|
||||
<input type="text" name="shipping_method_title[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php _e( 'Label', 'woocommerce' ); ?>" value="<?php echo esc_attr( $shipping_title ); ?>" class="first" />
|
||||
<input type="hidden" name="shipping_method_id[<?php echo $item_id ? $item_id : 'new][]'; ?>]" value="<?php echo esc_attr( $item_id ); ?>" />
|
||||
</p>
|
||||
<p class="first">
|
||||
<select name="shipping_method[<?php echo $item_id ? $item_id : 'new][]'; ?>]" class="first">
|
||||
<optgroup label="<?php _e( 'Shipping Method', 'woocommerce' ); ?>">
|
||||
<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
$found_method = false;
|
||||
<tr class="shipping <?php echo ( ! empty( $class ) ) ? $class : ''; ?>" data-order_item_id="<?php echo $item_id; ?>">
|
||||
<td class="check-column"><input type="checkbox" /></td>
|
||||
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
<td class="thumb"></td>
|
||||
|
||||
if ( strpos( $chosen_method, $method->id ) === 0 )
|
||||
$value = $chosen_method;
|
||||
else
|
||||
$value = $method->id;
|
||||
<td class="name">
|
||||
<div class="view">
|
||||
<?php echo ! empty( $item['name'] ) ? esc_html( $item['name'] ) : __( 'Shipping', 'woocommerce' ); ?>
|
||||
</div>
|
||||
<div class="edit" style="display: none;">
|
||||
<input type="text" placeholder="<?php _e( 'Shipping Name', 'woocommerce' ); ?>" name="shipping_method_title[<?php echo $item_id; ?>]" value="<?php echo ( isset( $item['name'] ) ) ? esc_attr( $item['name'] ) : ''; ?>" />
|
||||
<select name="shipping_method[<?php echo $item_id; ?>]">
|
||||
<optgroup label="<?php _e( 'Shipping Method', 'woocommerce' ); ?>">
|
||||
<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
$found_method = false;
|
||||
|
||||
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $chosen_method == $value, true, false ) . '>' . esc_html( $method->get_title() ) . '</option>';
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
$method_id = isset( $item['method_id'] ) ? $item['method_id'] : '';
|
||||
$current_method = ( 0 === strpos( $method_id, $method->id ) ) ? $method_id : $method->id;
|
||||
|
||||
if ( $chosen_method == $value )
|
||||
$found_method = true;
|
||||
}
|
||||
echo '<option value="' . esc_attr( $current_method ) . '" ' . selected( $method_id == $current_method, true, false ) . '>' . esc_html( $method->get_title() ) . '</option>';
|
||||
|
||||
if ( $method_id == $current_method ) {
|
||||
$found_method = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found_method && ! empty( $method_id ) ) {
|
||||
echo '<option value="' . esc_attr( $method_id ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
|
||||
} else {
|
||||
echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
</select>
|
||||
<input type="hidden" name="shipping_method_id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item_id ); ?>" />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="quantity" width="1%">1</td>
|
||||
|
||||
<td class="line_cost" width="1%">
|
||||
<div class="view">
|
||||
<?php echo ( isset( $item['cost'] ) ) ? wc_price( wc_round_tax_total( $item['cost'] ) ) : ''; ?>
|
||||
</div>
|
||||
<div class="edit" style="display: none;">
|
||||
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="shipping_cost[<?php echo $item_id; ?>]" 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' ) ) :
|
||||
$shipping_taxes = isset( $item['taxes'] ) ? $item['taxes'] : '';
|
||||
$tax_data = maybe_unserialize( $shipping_taxes );
|
||||
|
||||
foreach ( $order_taxes as $tax_item ) :
|
||||
$tax_item_id = $tax_item['rate_id'];
|
||||
$tax_item_total = isset( $tax_data[ $tax_item_id ] ) ? $tax_data[ $tax_item_id ] : '';
|
||||
|
||||
if ( ! $found_method && ! empty( $chosen_method ) ) {
|
||||
echo '<option value="' . esc_attr( $chosen_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
|
||||
} else {
|
||||
echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</optgroup>
|
||||
</select>
|
||||
</p>
|
||||
<p class="last">
|
||||
<input type="text" class="shipping_cost wc_input_price" name="shipping_cost[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $shipping_cost ) ); ?>" />
|
||||
</p>
|
||||
<?php do_action( 'woocommerce_admin_order_totals_after_shipping_item', $item_id ); ?>
|
||||
<a href="#" class="delete_total_row">×</a>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
<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="shipping_taxes[<?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
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
|
||||
<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="refund-quantity" />
|
||||
</td>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<div class="total_row tax_row" data-order_item_id="<?php echo $item_id; ?>">
|
||||
<p class="wide">
|
||||
<select name="order_taxes_rate_id[<?php echo $item_id ? $item_id : 'new][]'; ?>]">
|
||||
<optgroup label="<?php _e( 'Tax Rate', 'woocommerce' ); ?>">
|
||||
<option value=""><?php _e( 'N/A', 'woocommerce' ); ?></option>
|
||||
<?php foreach( $tax_codes as $tax_id => $tax_code ) : ?>
|
||||
<option value="<?php echo $tax_id; ?>" <?php selected( $tax_id, isset( $item['rate_id'] ) ? $item['rate_id'] : '' ); ?>><?php echo esc_html( urldecode( $tax_code ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</optgroup>
|
||||
</select>
|
||||
<input type="hidden" name="order_taxes_id[<?php echo $item_id ? $item_id : 'new][]'; ?>]" value="<?php echo esc_attr( $item_id ); ?>" />
|
||||
</p>
|
||||
<p class="first">
|
||||
<label><?php _e( 'Sales Tax', 'woocommerce' ) ?></label>
|
||||
<input type="text" class="order_taxes_amount wc_input_price" name="order_taxes_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['tax_amount'] ) ) echo esc_attr( wc_format_localized_price( $item['tax_amount'] ) ); ?>" />
|
||||
</p>
|
||||
<p class="last">
|
||||
<label><?php _e( 'Shipping Tax', 'woocommerce' ) ?></label>
|
||||
<input type="text" class="order_taxes_shipping_amount wc_input_price" name="order_taxes_shipping_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['shipping_tax_amount'] ) ) echo esc_attr( wc_format_localized_price( $item['shipping_tax_amount'] ) ); ?>" />
|
||||
</p>
|
||||
<a href="#" class="delete_total_row">×</a>
|
||||
<div class="clear"></div>
|
||||
</div>
|
|
@ -17,28 +17,28 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
*/
|
||||
function wc_get_screen_ids() {
|
||||
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
|
||||
$screen_ids = array(
|
||||
'toplevel_page_' . $wc_screen_id,
|
||||
$wc_screen_id . '_page_wc-reports',
|
||||
$wc_screen_id . '_page_wc-settings',
|
||||
$wc_screen_id . '_page_wc-status',
|
||||
$wc_screen_id . '_page_wc-addons',
|
||||
'product_page_product_attributes',
|
||||
'edit-product',
|
||||
'product',
|
||||
'edit-shop_coupon',
|
||||
'shop_coupon',
|
||||
'edit-product_cat',
|
||||
'edit-product_tag',
|
||||
'edit-product_shipping_class'
|
||||
);
|
||||
$screen_ids = array(
|
||||
'toplevel_page_' . $wc_screen_id,
|
||||
$wc_screen_id . '_page_wc-reports',
|
||||
$wc_screen_id . '_page_wc-settings',
|
||||
$wc_screen_id . '_page_wc-status',
|
||||
$wc_screen_id . '_page_wc-addons',
|
||||
'product_page_product_attributes',
|
||||
'edit-product',
|
||||
'product',
|
||||
'edit-shop_coupon',
|
||||
'shop_coupon',
|
||||
'edit-product_cat',
|
||||
'edit-product_tag',
|
||||
'edit-product_shipping_class'
|
||||
);
|
||||
|
||||
foreach ( wc_get_order_types() as $type ) {
|
||||
$screen_ids[] = $type;
|
||||
$screen_ids[] = 'edit-' . $type;
|
||||
}
|
||||
foreach ( wc_get_order_types() as $type ) {
|
||||
$screen_ids[] = $type;
|
||||
$screen_ids[] = 'edit-' . $type;
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_screen_ids', $screen_ids );
|
||||
return apply_filters( 'woocommerce_screen_ids', $screen_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,46 +53,46 @@ function wc_get_screen_ids() {
|
|||
* @return int page ID
|
||||
*/
|
||||
function wc_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
|
||||
global $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
$option_value = get_option( $option );
|
||||
$option_value = get_option( $option );
|
||||
|
||||
if ( $option_value > 0 && get_post( $option_value ) )
|
||||
return -1;
|
||||
if ( $option_value > 0 && get_post( $option_value ) )
|
||||
return -1;
|
||||
|
||||
$page_found = null;
|
||||
$page_found = null;
|
||||
|
||||
if ( strlen( $page_content ) > 0 ) {
|
||||
// Search for an existing page with the specified page content (typically a shortcode)
|
||||
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
|
||||
} else {
|
||||
// Search for an existing page with the specified page slug
|
||||
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", $slug ) );
|
||||
}
|
||||
if ( strlen( $page_content ) > 0 ) {
|
||||
// Search for an existing page with the specified page content (typically a shortcode)
|
||||
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
|
||||
} else {
|
||||
// Search for an existing page with the specified page slug
|
||||
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", $slug ) );
|
||||
}
|
||||
|
||||
if ( $page_found ) {
|
||||
if ( ! $option_value )
|
||||
update_option( $option, $page_found );
|
||||
|
||||
if ( $page_found ) {
|
||||
if ( ! $option_value )
|
||||
update_option( $option, $page_found );
|
||||
|
||||
return $page_found;
|
||||
}
|
||||
}
|
||||
|
||||
$page_data = array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_author' => 1,
|
||||
'post_name' => $slug,
|
||||
'post_title' => $page_title,
|
||||
'post_content' => $page_content,
|
||||
'post_parent' => $post_parent,
|
||||
'comment_status' => 'closed'
|
||||
);
|
||||
$page_id = wp_insert_post( $page_data );
|
||||
$page_data = array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_author' => 1,
|
||||
'post_name' => $slug,
|
||||
'post_title' => $page_title,
|
||||
'post_content' => $page_content,
|
||||
'post_parent' => $post_parent,
|
||||
'comment_status' => 'closed'
|
||||
);
|
||||
$page_id = wp_insert_post( $page_data );
|
||||
|
||||
if ( $option )
|
||||
update_option( $option, $page_id );
|
||||
if ( $option )
|
||||
update_option( $option, $page_id );
|
||||
|
||||
return $page_id;
|
||||
return $page_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,10 +103,10 @@ function wc_create_page( $slug, $option = '', $page_title = '', $page_content =
|
|||
* @param array $options Opens array to output
|
||||
*/
|
||||
function woocommerce_admin_fields( $options ) {
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
|
||||
WC_Admin_Settings::output_fields( $options );
|
||||
WC_Admin_Settings::output_fields( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,10 +117,10 @@ function woocommerce_admin_fields( $options ) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_update_options( $options ) {
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
|
||||
WC_Admin_Settings::save_fields( $options );
|
||||
WC_Admin_Settings::save_fields( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,10 +130,10 @@ function woocommerce_update_options( $options ) {
|
|||
* @return string
|
||||
*/
|
||||
function woocommerce_settings_get_option( $option_name, $default = '' ) {
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
if ( ! class_exists( 'WC_Admin_Settings' ) )
|
||||
include 'class-wc-admin-settings.php';
|
||||
|
||||
return WC_Admin_Settings::get_option( $option_name, $default );
|
||||
return WC_Admin_Settings::get_option( $option_name, $default );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,30 +143,30 @@ function woocommerce_settings_get_option( $option_name, $default = '' ) {
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_compile_less_styles() {
|
||||
$colors = array_map( 'esc_attr', (array) get_option( 'woocommerce_frontend_css_colors' ) );
|
||||
$base_file = WC()->plugin_path() . '/assets/css/woocommerce-base.less';
|
||||
$less_file = WC()->plugin_path() . '/assets/css/woocommerce.less';
|
||||
$css_file = WC()->plugin_path() . '/assets/css/woocommerce.css';
|
||||
$colors = array_map( 'esc_attr', (array) get_option( 'woocommerce_frontend_css_colors' ) );
|
||||
$base_file = WC()->plugin_path() . '/assets/css/woocommerce-base.less';
|
||||
$less_file = WC()->plugin_path() . '/assets/css/woocommerce.less';
|
||||
$css_file = WC()->plugin_path() . '/assets/css/woocommerce.css';
|
||||
|
||||
// Write less file
|
||||
if ( is_writable( $base_file ) && is_writable( $css_file ) ) {
|
||||
// Write less file
|
||||
if ( is_writable( $base_file ) && is_writable( $css_file ) ) {
|
||||
|
||||
// Colours changed - recompile less
|
||||
if ( ! class_exists( 'lessc' ) )
|
||||
include_once( WC()->plugin_path() . '/includes/libraries/class-lessc.php' );
|
||||
if ( ! class_exists( 'cssmin' ) )
|
||||
include_once( WC()->plugin_path() . '/includes/libraries/class-cssmin.php' );
|
||||
// Colours changed - recompile less
|
||||
if ( ! class_exists( 'lessc' ) )
|
||||
include_once( WC()->plugin_path() . '/includes/libraries/class-lessc.php' );
|
||||
if ( ! class_exists( 'cssmin' ) )
|
||||
include_once( WC()->plugin_path() . '/includes/libraries/class-cssmin.php' );
|
||||
|
||||
try {
|
||||
// Set default if colours not set
|
||||
if ( ! $colors['primary'] ) $colors['primary'] = '#ad74a2';
|
||||
if ( ! $colors['secondary'] ) $colors['secondary'] = '#f7f6f7';
|
||||
if ( ! $colors['highlight'] ) $colors['highlight'] = '#85ad74';
|
||||
if ( ! $colors['content_bg'] ) $colors['content_bg'] = '#ffffff';
|
||||
if ( ! $colors['subtext'] ) $colors['subtext'] = '#777777';
|
||||
try {
|
||||
// Set default if colours not set
|
||||
if ( ! $colors['primary'] ) $colors['primary'] = '#ad74a2';
|
||||
if ( ! $colors['secondary'] ) $colors['secondary'] = '#f7f6f7';
|
||||
if ( ! $colors['highlight'] ) $colors['highlight'] = '#85ad74';
|
||||
if ( ! $colors['content_bg'] ) $colors['content_bg'] = '#ffffff';
|
||||
if ( ! $colors['subtext'] ) $colors['subtext'] = '#777777';
|
||||
|
||||
// Write new color to base file
|
||||
$color_rules = "
|
||||
// Write new color to base file
|
||||
$color_rules = "
|
||||
@primary: " . $colors['primary'] . ";
|
||||
@primarytext: " . wc_light_or_dark( $colors['primary'], 'desaturate(darken(@primary,50%),18%)', 'desaturate(lighten(@primary,50%),18%)' ) . ";
|
||||
|
||||
|
@ -179,19 +179,214 @@ function woocommerce_compile_less_styles() {
|
|||
@contentbg: " . $colors['content_bg'] . ";
|
||||
|
||||
@subtext: " . $colors['subtext'] . ";
|
||||
";
|
||||
";
|
||||
|
||||
file_put_contents( $base_file, $color_rules );
|
||||
file_put_contents( $base_file, $color_rules );
|
||||
|
||||
$less = new lessc;
|
||||
$compiled_css = $less->compileFile( $less_file );
|
||||
$compiled_css = CssMin::minify( $compiled_css );
|
||||
$less = new lessc;
|
||||
$compiled_css = $less->compileFile( $less_file );
|
||||
$compiled_css = CssMin::minify( $compiled_css );
|
||||
|
||||
if ( $compiled_css )
|
||||
file_put_contents( $css_file, $compiled_css );
|
||||
if ( $compiled_css )
|
||||
file_put_contents( $css_file, $compiled_css );
|
||||
|
||||
} catch ( exception $ex ) {
|
||||
wp_die( __( 'Could not compile woocommerce.less:', 'woocommerce' ) . ' ' . $ex->getMessage() );
|
||||
}
|
||||
}
|
||||
} catch ( exception $ex ) {
|
||||
wp_die( __( 'Could not compile woocommerce.less:', 'woocommerce' ) . ' ' . $ex->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$taxes = array( 'items' => array(), 'shipping' => array() );
|
||||
|
||||
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_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_total', wc_format_decimal( $line_total[ $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 ) );
|
||||
$taxes['items'][] = $tax_data_total;
|
||||
|
||||
// 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', 'shipping_taxes' );
|
||||
|
||||
foreach ( $get_values as $value ) {
|
||||
$$value = isset( $items[ $value ] ) ? $items[ $value ] : array();
|
||||
}
|
||||
|
||||
foreach ( $shipping_method_id as $item_id => $value ) {
|
||||
$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 ] );
|
||||
$ship_taxes = isset( $shipping_taxes[ $item_id ] ) ? array_map( 'wc_format_decimal', $shipping_taxes[ $item_id ] ) : array();
|
||||
|
||||
$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 );
|
||||
wc_update_order_item_meta( $item_id, 'taxes', $ship_taxes );
|
||||
|
||||
$taxes['shipping'][] = $ship_taxes;
|
||||
|
||||
$order_shipping += $cost;
|
||||
}
|
||||
}
|
||||
|
||||
// Taxes
|
||||
$order_taxes = isset( $items['order_taxes'] ) ? $items['order_taxes'] : array();
|
||||
$taxes_items = array();
|
||||
$taxes_shipping = array();
|
||||
$total_tax = 0;
|
||||
$total_shipping_tax = 0;
|
||||
|
||||
// Sum items taxes
|
||||
foreach ( $taxes['items'] as $rates ) {
|
||||
foreach ( $rates as $id => $value ) {
|
||||
if ( isset( $taxes_items[ $id ] ) ) {
|
||||
$taxes_items[ $id ] += $value;
|
||||
} else {
|
||||
$taxes_items[ $id ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sum shipping taxes
|
||||
foreach ( $taxes['shipping'] as $rates ) {
|
||||
foreach ( $rates as $id => $value ) {
|
||||
if ( isset( $taxes_shipping[ $id ] ) ) {
|
||||
$taxes_shipping[ $id ] += $value;
|
||||
} else {
|
||||
$taxes_shipping[ $id ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update order taxes
|
||||
foreach ( $order_taxes as $item_id => $rate_id ) {
|
||||
if ( isset( $taxes_items[ $rate_id ] ) ) {
|
||||
$_total = wc_format_decimal( $taxes_items[ $rate_id ] );
|
||||
wc_update_order_item_meta( $item_id, 'tax_amount', $_total );
|
||||
|
||||
$total_tax += $_total;
|
||||
}
|
||||
|
||||
if ( isset( $taxes_shipping[ $rate_id ] ) ) {
|
||||
$_total = wc_format_decimal( $taxes_shipping[ $rate_id ] );
|
||||
wc_update_order_item_meta( $item_id, 'shipping_tax_amount', $_total );
|
||||
|
||||
$total_shipping_tax += $_total;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 );
|
||||
|
||||
// Update totals
|
||||
update_post_meta( $order_id, '_order_discount', wc_format_decimal( $items['_order_discount'] ) );
|
||||
update_post_meta( $order_id, '_order_total', wc_format_decimal( $items['_order_total'] ) );
|
||||
|
||||
// Update tax
|
||||
update_post_meta( $order_id, '_order_tax', wc_format_decimal( $total_tax ) );
|
||||
update_post_meta( $order_id, '_order_shipping_tax', wc_format_decimal( $total_shipping_tax ) );
|
||||
|
||||
// Remove old values
|
||||
delete_post_meta( $order_id, '_shipping_method' );
|
||||
delete_post_meta( $order_id, '_shipping_method_title' );
|
||||
|
||||
// Set the currency
|
||||
add_post_meta( $order_id, '_order_currency', get_woocommerce_currency(), true );
|
||||
}
|
||||
|
|
|
@ -44,12 +44,17 @@ class WC_AJAX {
|
|||
'get_customer_details' => false,
|
||||
'add_order_item' => false,
|
||||
'add_order_fee' => false,
|
||||
'add_order_shipping' => false,
|
||||
'add_order_tax' => false,
|
||||
'remove_order_item' => false,
|
||||
'remote_order_tax' => false,
|
||||
'reduce_order_item_stock' => false,
|
||||
'increase_order_item_stock' => false,
|
||||
'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,
|
||||
|
@ -937,9 +942,10 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
$_product = get_product( $post->ID );
|
||||
$order = get_order( $order_id );
|
||||
$class = 'new_row';
|
||||
$_product = get_product( $post->ID );
|
||||
$order = get_order( $order_id );
|
||||
$order_taxes = $order->get_taxes();
|
||||
$class = 'new_row';
|
||||
|
||||
// Set values
|
||||
$item = array();
|
||||
|
@ -972,6 +978,9 @@ class WC_AJAX {
|
|||
wc_add_order_item_meta( $item_id, '_line_total', $item['line_total'] );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax', $item['line_tax'] );
|
||||
|
||||
// Since 2.2
|
||||
wc_add_order_item_meta( $item_id, '_line_tax_data', array( 'total' => array(), 'subtotal' => array() ) );
|
||||
|
||||
// Store variation data in meta
|
||||
if ( $item['variation_data'] && is_array( $item['variation_data'] ) ) {
|
||||
foreach ( $item['variation_data'] as $key => $value ) {
|
||||
|
@ -997,8 +1006,9 @@ class WC_AJAX {
|
|||
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = get_order( $order_id );
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = get_order( $order_id );
|
||||
$order_taxes = $order->get_taxes();
|
||||
|
||||
// Add line item
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
|
@ -1011,6 +1021,9 @@ class WC_AJAX {
|
|||
wc_add_order_item_meta( $item_id, '_tax_class', '' );
|
||||
wc_add_order_item_meta( $item_id, '_line_total', '' );
|
||||
wc_add_order_item_meta( $item_id, '_line_tax', '' );
|
||||
|
||||
// Since 2.2
|
||||
wc_add_order_item_meta( $item_id, '_line_tax_data', array( 'total' => array() ) );
|
||||
}
|
||||
|
||||
include( 'admin/meta-boxes/views/html-order-fee.php' );
|
||||
|
@ -1019,6 +1032,81 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order shipping cost via ajax
|
||||
*/
|
||||
public static function add_order_shipping() {
|
||||
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = get_order( $order_id );
|
||||
$order_taxes = $order->get_taxes();
|
||||
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
|
||||
|
||||
// Add line item
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
'order_item_name' => '',
|
||||
'order_item_type' => 'shipping'
|
||||
) );
|
||||
|
||||
// Add line item meta
|
||||
if ( $item_id ) {
|
||||
wc_add_order_item_meta( $item_id, 'method_id', '' );
|
||||
wc_add_order_item_meta( $item_id, 'cost', '' );
|
||||
wc_add_order_item_meta( $item_id, 'taxes', array() );
|
||||
}
|
||||
|
||||
include( 'admin/meta-boxes/views/html-order-shipping.php' );
|
||||
|
||||
// Quit out
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order tax column via ajax
|
||||
*/
|
||||
public static function add_order_tax() {
|
||||
global $wpdb;
|
||||
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$rate_id = absint( $_POST['rate_id'] );
|
||||
|
||||
$rate = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id ) );
|
||||
$label = $rate->tax_rate_name ? $rate->tax_rate_name : WC()->countries->tax_or_vat();
|
||||
$compound = $rate->tax_rate_compound ? 1 : 0;
|
||||
$code = array();
|
||||
$code[] = $rate->tax_rate_country;
|
||||
$code[] = $rate->tax_rate_state;
|
||||
$code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
|
||||
$code[] = absint( $rate->tax_rate_priority );
|
||||
$code = strtoupper( implode( '-', array_filter( $code ) ) );
|
||||
|
||||
// Add line item
|
||||
$new_id = wc_add_order_item( $order_id, array(
|
||||
'order_item_name' => wc_clean( $code ),
|
||||
'order_item_type' => 'tax'
|
||||
) );
|
||||
|
||||
// Add line item meta
|
||||
if ( $new_id ) {
|
||||
wc_add_order_item_meta( $new_id, 'rate_id', $rate_id );
|
||||
wc_add_order_item_meta( $new_id, 'label', $label );
|
||||
wc_add_order_item_meta( $new_id, 'compound', $compound );
|
||||
wc_add_order_item_meta( $new_id, 'tax_amount', wc_format_decimal( 0 ) );
|
||||
wc_add_order_item_meta( $new_id, 'shipping_tax_amount', wc_format_decimal( 0 ) );
|
||||
}
|
||||
|
||||
// Return HTML items
|
||||
$order = new WC_Order( $order_id );
|
||||
$data = get_post_meta( $order_id );
|
||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an order item
|
||||
*/
|
||||
|
@ -1040,6 +1128,26 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an order tax
|
||||
*/
|
||||
public static function remote_order_tax() {
|
||||
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$rate_id = absint( $_POST['rate_id'] );
|
||||
|
||||
wc_delete_order_item( $rate_id );
|
||||
|
||||
// Return HTML items
|
||||
$order = new WC_Order( $order_id );
|
||||
$data = get_post_meta( $order_id );
|
||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce order item stock
|
||||
*/
|
||||
|
@ -1277,6 +1385,46 @@ 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 );
|
||||
$data = get_post_meta( $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 );
|
||||
$data = get_post_meta( $order_id );
|
||||
include( 'admin/meta-boxes/views/html-order-items.php' );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order note via ajax
|
||||
*/
|
||||
|
@ -1653,7 +1801,7 @@ class WC_AJAX {
|
|||
if ( ! $refund_amount || $max_refund < $refund_amount ) {
|
||||
throw new exception( __( 'Invalid refund amount', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
|
||||
// Create the refund object
|
||||
$refund = wc_create_refund( array(
|
||||
'amount' => $refund_amount,
|
||||
|
@ -1695,7 +1843,7 @@ class WC_AJAX {
|
|||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$refund_id = absint( $_POST['refund_id'] );
|
||||
|
||||
|
||||
if ( $refund_id && 'shop_order_refund' === get_post_type( $refund_id ) ) {
|
||||
wp_delete_post( $refund_id );
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class WC_Cart {
|
|||
$this->dp = absint( get_option( 'woocommerce_price_num_decimals' ) );
|
||||
$this->display_totals_ex_tax = $this->tax_display_cart == 'excl';
|
||||
$this->display_cart_ex_tax = $this->tax_display_cart == 'excl';
|
||||
|
||||
|
||||
// Array of data the cart calculates and stores in the session with defaults
|
||||
$this->cart_session_data = array(
|
||||
'cart_contents_total' => 0,
|
||||
|
@ -334,7 +334,7 @@ class WC_Cart {
|
|||
// Check item stock
|
||||
$result = $this->check_cart_item_stock();
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wc_add_notice( $result->get_error_message(), 'error' );
|
||||
}
|
||||
}
|
||||
|
@ -804,10 +804,10 @@ class WC_Cart {
|
|||
|
||||
// Load cart item data - may be added by other plugins
|
||||
$cart_item_data = (array) apply_filters( 'woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id );
|
||||
|
||||
|
||||
// Generate a ID based on product ID, variation ID, variation data, and other cart item data
|
||||
$cart_id = $this->generate_cart_id( $product_id, $variation_id, $variation, $cart_item_data );
|
||||
|
||||
|
||||
// See if this product and its options is already in the cart
|
||||
$cart_item_key = $this->find_product_in_cart( $cart_id );
|
||||
|
||||
|
@ -816,7 +816,7 @@ class WC_Cart {
|
|||
$variation_id = $product_id;
|
||||
$product_id = wp_get_post_parent_id( $variation_id );
|
||||
}
|
||||
|
||||
|
||||
// Get the product
|
||||
$product_data = get_product( $variation_id ? $variation_id : $product_id );
|
||||
|
||||
|
@ -1001,7 +1001,7 @@ class WC_Cart {
|
|||
// Prices
|
||||
$base_price = $_product->get_price();
|
||||
$line_price = $_product->get_price() * $values['quantity'];
|
||||
|
||||
|
||||
$line_subtotal = 0;
|
||||
$line_subtotal_tax = 0;
|
||||
|
||||
|
@ -1100,6 +1100,10 @@ class WC_Cart {
|
|||
$base_price = $_product->get_price();
|
||||
$line_price = $_product->get_price() * $values['quantity'];
|
||||
|
||||
// Tax data
|
||||
$taxes = array();
|
||||
$discounted_taxes = array();
|
||||
|
||||
/**
|
||||
* No tax to calculate
|
||||
*/
|
||||
|
@ -1204,10 +1208,13 @@ class WC_Cart {
|
|||
$this->cart_contents_total += $line_total;
|
||||
|
||||
// Store costs + taxes for lines
|
||||
$this->cart_contents[ $cart_item_key ]['line_total'] = $line_total;
|
||||
$this->cart_contents[ $cart_item_key ]['line_tax'] = $line_tax;
|
||||
$this->cart_contents[ $cart_item_key ]['line_subtotal'] = $line_subtotal;
|
||||
$this->cart_contents[ $cart_item_key ]['line_total'] = $line_total;
|
||||
$this->cart_contents[ $cart_item_key ]['line_tax'] = $line_tax;
|
||||
$this->cart_contents[ $cart_item_key ]['line_subtotal'] = $line_subtotal;
|
||||
$this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $line_subtotal_tax;
|
||||
|
||||
// Store rates ID and costs - Since 2.2
|
||||
$this->cart_contents[ $cart_item_key ]['line_tax_data'] = array( 'total' => $taxes, 'subtotal' => $discounted_taxes );
|
||||
}
|
||||
|
||||
// Only calculate the grand total + shipping if on the cart/checkout
|
||||
|
@ -1376,7 +1383,7 @@ class WC_Cart {
|
|||
|
||||
/**
|
||||
* Should the shipping address form be shown
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function needs_shipping_address() {
|
||||
|
@ -1523,7 +1530,7 @@ class WC_Cart {
|
|||
$usage_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ( $check_emails as $check_email ) {
|
||||
$usage_count = $usage_count + sizeof( array_keys( $used_by, $check_email ) );
|
||||
}
|
||||
|
@ -1872,14 +1879,15 @@ class WC_Cart {
|
|||
}
|
||||
}
|
||||
|
||||
$new_fee = new stdClass();
|
||||
$new_fee->id = $new_fee_id;
|
||||
$new_fee->name = esc_attr( $name );
|
||||
$new_fee->amount = (float) esc_attr( $amount );
|
||||
$new_fee->tax_class = $tax_class;
|
||||
$new_fee->taxable = $taxable ? true : false;
|
||||
$new_fee->tax = 0;
|
||||
$this->fees[] = $new_fee;
|
||||
$new_fee = new stdClass();
|
||||
$new_fee->id = $new_fee_id;
|
||||
$new_fee->name = esc_attr( $name );
|
||||
$new_fee->amount = (float) esc_attr( $amount );
|
||||
$new_fee->tax_class = $tax_class;
|
||||
$new_fee->taxable = $taxable ? true : false;
|
||||
$new_fee->tax = 0;
|
||||
$new_fee->tax_data = array();
|
||||
$this->fees[] = $new_fee;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1909,11 +1917,14 @@ class WC_Cart {
|
|||
// Get tax rates
|
||||
$tax_rates = $this->tax->get_rates( $fee->tax_class );
|
||||
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
|
||||
|
||||
|
||||
if ( ! empty( $fee_taxes ) ) {
|
||||
// Set the tax total for this fee
|
||||
$this->fees[ $fee_key ]->tax = array_sum( $fee_taxes );
|
||||
|
||||
// Set tax data - Since 2.2
|
||||
$this->fees[ $fee_key ]->tax_data = $fee_taxes;
|
||||
|
||||
// Tax rows - merge the totals we just got
|
||||
foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) {
|
||||
$this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
|
||||
|
|
|
@ -204,16 +204,17 @@ class WC_Checkout {
|
|||
|
||||
// Store the line items to the new/resumed order
|
||||
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
|
||||
$item_id = $order->add_product(
|
||||
$values['data'],
|
||||
$values['quantity'],
|
||||
$item_id = $order->add_product(
|
||||
$values['data'],
|
||||
$values['quantity'],
|
||||
array(
|
||||
'variation' => $values['variation'],
|
||||
'totals' => array(
|
||||
'subtotal' => $values['line_subtotal'],
|
||||
'subtotal_tax' => $values['line_subtotal_tax'],
|
||||
'total' => $values['line_total'],
|
||||
'tax' => $values['line_tax']
|
||||
'tax' => $values['line_tax'],
|
||||
'tax_data' => $values['line_tax_data'] // Since 2.2
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -233,7 +234,7 @@ class WC_Checkout {
|
|||
if ( ! $item_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
|
||||
// Allow plugins to add order item meta to fees
|
||||
do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
|
||||
}
|
||||
|
@ -246,7 +247,7 @@ class WC_Checkout {
|
|||
if ( ! $item_id ) {
|
||||
throw new Exception( __( 'Error: Unable to create order. Please try again.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
|
||||
// Allows plugins to add order item meta to shipping
|
||||
do_action( 'woocommerce_add_shipping_order_item', $order_id, $item_id, $package_key );
|
||||
}
|
||||
|
@ -517,7 +518,7 @@ class WC_Checkout {
|
|||
|
||||
if ( WC()->cart->needs_shipping() ) {
|
||||
|
||||
if ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) )
|
||||
if ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) )
|
||||
wc_add_notice( sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ), 'error' );
|
||||
|
||||
// Validate Shipping Methods
|
||||
|
@ -571,15 +572,15 @@ class WC_Checkout {
|
|||
|
||||
// As we are now logged in, checkout will need to refresh to show logged in data
|
||||
WC()->session->set( 'reload_checkout', true );
|
||||
|
||||
|
||||
// Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
|
||||
WC()->cart->calculate_totals();
|
||||
|
||||
// Add customer info from other billing fields
|
||||
if ( $this->posted['billing_first_name'] && apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) {
|
||||
$userdata = array(
|
||||
'ID' => $this->customer_id,
|
||||
'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '',
|
||||
$userdata = array(
|
||||
'ID' => $this->customer_id,
|
||||
'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '',
|
||||
'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '',
|
||||
'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : ''
|
||||
);
|
||||
|
|
|
@ -62,7 +62,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
FROM $wpdb->postmeta AS postmeta
|
||||
INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
|
||||
WHERE postmeta.meta_key = '_refund_amount'
|
||||
GROUP BY posts.ID
|
||||
AND postmeta.post_id = posts.ID
|
||||
", $this->id ) );
|
||||
|
||||
return $total;
|
||||
|
|
|
@ -54,4 +54,4 @@ class WC_Shipping_Rate {
|
|||
}
|
||||
return $taxes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -570,3 +570,18 @@ function wc_create_refund( $args = array() ) {
|
|||
|
||||
return new WC_Order_Refund( $refund_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tax class by tax id.
|
||||
*
|
||||
* @since 2.2
|
||||
* @param int $tax_id
|
||||
* @return string
|
||||
*/
|
||||
function wc_get_tax_class_by_tax_id( $tax_id ) {
|
||||
global $wpdb;
|
||||
|
||||
$tax_class = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_class FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d", $tax_id ) );
|
||||
|
||||
return wc_clean( $tax_class );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue