Coded in Restore stock option
This commit is contained in:
parent
a7eaefc374
commit
710a570525
|
@ -695,6 +695,7 @@ jQuery( function ( $ ) {
|
|||
line_item_totals: JSON.stringify( line_item_totals, null, '' ),
|
||||
line_item_tax_totals: JSON.stringify( line_item_tax_totals, null, '' ),
|
||||
api_refund: $( this ).is( '.do-api-refund' ),
|
||||
restock_refunded_items: $( '#restock_refunded_items:checked' ).size() ? 'true' : 'false',
|
||||
security: woocommerce_admin_meta_boxes.order_item_nonce
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1798,10 +1798,12 @@ class WC_AJAX {
|
|||
$line_item_totals = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_totals'] ) ), true );
|
||||
$line_item_tax_totals = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_tax_totals'] ) ), true );
|
||||
$api_refund = $_POST['api_refund'] === 'true' ? true : false;
|
||||
$restock_refunded_items = $_POST['restock_refunded_items'] === 'true' ? true : false;
|
||||
|
||||
try {
|
||||
// Validate that the refund can occur
|
||||
$order = get_order( $order_id );
|
||||
$order_items = $order->get_items();
|
||||
$max_refund = $order->get_total() - $order->get_total_refunded();
|
||||
|
||||
if ( ! $refund_amount || $max_refund < $refund_amount ) {
|
||||
|
@ -1817,6 +1819,18 @@ class WC_AJAX {
|
|||
}
|
||||
foreach ( $line_item_qtys as $item_id => $qty ) {
|
||||
$line_items[ $item_id ]['qty'] = max( $qty, 0 );
|
||||
|
||||
if ( $restock_refunded_items && $qty && isset( $order_items[ $item_id ] ) ) {
|
||||
$order_item = $order_items[ $item_id ];
|
||||
$_product = $order->get_product_from_item( $order_item );
|
||||
|
||||
if ( $_product && $_product->exists() && $_product->managing_stock() ) {
|
||||
$old_stock = $_product->stock;
|
||||
$new_quantity = $_product->increase_stock( $qty );
|
||||
|
||||
$order->add_order_note( sprintf( __( 'Item #%s stock increased from %s to %s.', 'woocommerce' ), $order_item['product_id'], $old_stock, $new_quantity ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $line_item_totals as $item_id => $total ) {
|
||||
$line_items[ $item_id ]['refund_total'] = $total;
|
||||
|
|
Loading…
Reference in New Issue