Merged 'refunds' into 'fees-and-shipping'. Closes #1746
This commit is contained in:
commit
3da5ccdafe
|
@ -367,7 +367,20 @@ function woocommerce_order_items_meta_box( $post ) {
|
|||
<option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
|
||||
<optgroup label="<?php _e( 'Edit', 'woocommerce' ); ?>">
|
||||
<option value="delete"><?php _e( 'Delete Lines', 'woocommerce' ); ?></option>
|
||||
<option value="refund"><?php _e( 'Refund Lines', 'woocommerce' ); ?></option>
|
||||
|
||||
<?php
|
||||
$gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
if ( isset( $gateways[ $order->payment_method ] ) ) {
|
||||
$gateway = $gateways[ $order->payment_method ];
|
||||
|
||||
if ( ! in_array( 'refunds', $gateway->supports ) || ! method_exists( $gateway, 'refund' ) ) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<option value="refund"' . $disabled . '>' . __( 'Refund Lines', 'woocommerce' ) . '</option>';
|
||||
?>
|
||||
</optgroup>
|
||||
<optgroup label="<?php _e( 'Stock Actions', 'woocommerce' ); ?>">
|
||||
<option value="reduce_stock"><?php _e( 'Reduce Line Stock', 'woocommerce' ); ?></option>
|
||||
|
|
|
@ -406,6 +406,7 @@ function woocommerce_admin_scripts() {
|
|||
'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),
|
||||
'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ),
|
||||
'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ),
|
||||
'refund_item_notice' => __( 'Are you sure you want to refund the selected items? The item\'s stock will not be affected.', 'woocommerce' ),
|
||||
'name_label' => __( 'Name', 'woocommerce' ),
|
||||
'remove_label' => __( 'Remove', 'woocommerce' ),
|
||||
'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ),
|
||||
|
|
|
@ -631,7 +631,31 @@ jQuery( function($){
|
|||
|
||||
} else if ( action == 'refund' ) {
|
||||
|
||||
// @todo refund handling
|
||||
var order_id = $('#post_ID').val();
|
||||
|
||||
var answer = confirm( woocommerce_writepanel_params.refund_item_notice );
|
||||
|
||||
if ( answer ) {
|
||||
|
||||
$('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
var data = {
|
||||
order_id: order_id,
|
||||
order_item_ids: item_ids,
|
||||
action: 'woocommerce_refund_order_item',
|
||||
security: woocommerce_writepanel_params.order_item_nonce
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
url: woocommerce_writepanel_params.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function( response ) {
|
||||
$('table.woocommerce_order_items').unblock();
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
} else if ( action == 'reduce_stock' ) {
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -945,6 +945,63 @@ function woocommerce_ajax_remove_order_item() {
|
|||
|
||||
add_action( 'wp_ajax_woocommerce_remove_order_item', 'woocommerce_ajax_remove_order_item' );
|
||||
|
||||
/**
|
||||
* woocommerce_ajax_refund_order_item function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_ajax_refund_order_item() {
|
||||
global $woocommerce, $wpdb;
|
||||
|
||||
check_ajax_referer( 'order-item', 'security' );
|
||||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$order = &new WC_Order( $order_id );
|
||||
|
||||
if ( $order ) {
|
||||
global $woocommerce;
|
||||
$gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
if ( isset( $gateways[ $order->payment_method ] ) ) {
|
||||
$gateway = $gateways[ $order->payment_method ];
|
||||
|
||||
if ( in_array( 'refunds', $gateway->supports ) && method_exists( $gateway, 'refund' ) ) {
|
||||
$order_item_ids = $_POST['order_item_ids'];
|
||||
|
||||
if ( sizeof( $order_item_ids ) > 0 ) {
|
||||
$refund_amount = 0;
|
||||
|
||||
foreach( $order_item_ids as $item_id ) {
|
||||
$amount = woocommerce_get_order_item_meta( $item_id, '_line_total', true );
|
||||
|
||||
if ( $gateway->refund( $order, absint( $item_id ), $amount ) ) {
|
||||
$refund_amount = $refund_amount + $amount;
|
||||
|
||||
woocommerce_update_order_item_meta( $item_id, '_refunded', true );
|
||||
do_action( 'woocommerce_refund_order_item', $item_id );
|
||||
}
|
||||
}
|
||||
|
||||
$order_refund_total = get_post_meta( $order_id, '_refund_total', true );
|
||||
|
||||
if ( ! $order_refund_total ) {
|
||||
$order_refund_total = $refund_amount;
|
||||
} else {
|
||||
$order_refund_total = $order_refund_total + $refund_amount;
|
||||
}
|
||||
|
||||
update_post_meta( $order_id, '_refund_total', woocommerce_format_total( $order_refund_total ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_woocommerce_refund_order_item', 'woocommerce_ajax_refund_order_item' );
|
||||
|
||||
/**
|
||||
* woocommerce_ajax_reduce_order_item_stock function.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue