Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Commit

Permalink
prevent order status changes on completed or refunded orders - fix #161
Browse files Browse the repository at this point in the history
  • Loading branch information
divergeinfinity committed Apr 9, 2012
1 parent 3c9e879 commit 6145418
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions admin/write-panels/order-data-save.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function jigoshop_process_shop_order_meta($post_id, $post)
//Get old order items
$old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true));

// Order status
if ( $order->update_status($_POST['order_status'] )) return; // there were errors with status changes, don't continue

// Add/Replace data to array
$order_fields = array(
'billing_first_name',
Expand Down Expand Up @@ -86,9 +89,6 @@ function jigoshop_process_shop_order_meta($post_id, $post)
// Customer
update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']);

// Order status
$order->update_status($_POST['order_status']);

// Order items
$order_items = array();

Expand Down
17 changes: 16 additions & 1 deletion classes/jigoshop_order.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,20 @@ function add_order_note( $note, $private = 1 ) {
*/
function update_status( $new_status, $note = '' ) {

if ( $this->status == 'completed' && $new_status != 'refunded' ) {
$jigoshop_errors = (array) maybe_unserialize(get_option('jigoshop_errors'));
$jigoshop_errors[] = __('Completed Orders may not be changed. You may only issue a Refund.','jigoshop');
update_option('jigoshop_errors', $jigoshop_errors );
return true;
}

if ( $this->status == 'refunded' ) {
$jigoshop_errors = (array) maybe_unserialize(get_option('jigoshop_errors'));
$jigoshop_errors[] = __('Refunded Orders may not be changed.','jigoshop');
update_option('jigoshop_errors', $jigoshop_errors );
return true;
}

if ($note) $note .= ' ';

$new_status = get_term_by( 'slug', sanitize_title( $new_status ), 'shop_order_status');
Expand All @@ -451,7 +465,8 @@ function update_status( $new_status, $note = '' ) {
endif;

endif;


return false; // signal no errors
}

/**
Expand Down

0 comments on commit 6145418

Please sign in to comment.