Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvola committed May 7, 2019
2 parents dd0df96 + 194480e commit 418e4ed
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.6.0](https://github.com/rvola/woo-cancel-abandoned-order/tree/1.6.0) - 2019-05-07
[Full Changelog](https://github.com/rvola/woo-cancel-abandoned-order/compare/1.5.1...1.6.0)
* NEW / Order status hook for the cancel process.
* MINOR / code style call Class external.

## [1.5.1](https://github.com/rvola/woo-cancel-abandoned-order/tree/1.5.1) - 2019-04-03
[Full Changelog](https://github.com/rvola/woo-cancel-abandoned-order/compare/1.5.0...1.5.1)

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ If you have check or transfer type orders for example, you will be able to set a

WooCommerce Cancel Abandoned Order, will take care of checking this and change the status of the order to "Cancel" if you have not received payment on time.

Since version **1.4.0** it's possible to cancel orders in hours ... Yeah!


## Installation

This section describes how to install the plugin and get it working.
Expand Down Expand Up @@ -44,6 +41,7 @@ _Filters_
* **woo_cao_date_order** ($old_date, $gateway, $mode) : Change the calculation date for pending orders.
* **woo_cao_default_hours** : Default value of the number of hours for order processing.
* **woo_cao_default_days** : Default value of the number of days for order processing.
* **woo_cao_statustocancel** ($status) : Allows you to add or change which WooCommerce order status the plugin should cancel.

## Wiki
* [A help section on the code is available here](https://github.com/rvola/woo-cancel-abandoned-order/wiki)
Expand All @@ -67,7 +65,12 @@ Mode **"Daily"**: every day at 0:00

If you checked the box to enable this feature in the gateway, the system will restock each product line of the abandoned order.

#### I would like to cancel orders pending payment

Follow the [tutorial here](https://github.com/rvola/woo-cancel-abandoned-order/wiki/Change-the-status-type-for-the-cancellation-process) to change the status of orders to cancel. By default the "on-hold" commands are canceled.

## Links

* [**Changelog**](https://github.com/rvola/woo-cancel-abandoned-order/blob/master/CHANGELOG.md)
* [**Download on WordPress**](https://wordpress.org/plugins/woo-cancel-abandoned-order/)
* [**WIKI**](https://github.com/rvola/woo-cancel-abandoned-order/wiki)
41 changes: 38 additions & 3 deletions includes/class-cao.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace RVOLA\WOO\CAO;

use WC_Order;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down Expand Up @@ -113,6 +115,9 @@ public function check_order() {
$old_date = apply_filters( 'woo_cao_date_order', $old_date, $gateway, $mode );
$old_date_format = date( 'Y-m-d 00:00:00', $old_date );

// Status to cancel
$woo_status = $this->woo_status();

$orders = $wpdb->get_results(
$wpdb->prepare(
"
Expand All @@ -121,7 +126,7 @@ public function check_order() {
INNER JOIN $wpdb->postmeta as meta
ON posts.ID = meta.post_id
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'wc-on-hold'
AND posts.post_status IN ('$woo_status')
AND posts.post_date < %s
AND meta.meta_key = '_payment_method'
AND meta.meta_value = %s
Expand Down Expand Up @@ -153,7 +158,7 @@ public function check_order() {
* @param int $order_id order ID.
*/
private function cancel_order( $order_id ) {
$order = new \WC_Order( $order_id );
$order = new WC_Order( $order_id );

$order->update_status(
'cancelled',
Expand All @@ -163,14 +168,44 @@ private function cancel_order( $order_id ) {

}

private function woo_status() {
$woo_status = array();
$woo_status_authorized = array(
'pending',
'on-hold',
'processing',
'completed',
'refunded',
'failed'
);

$default_status = apply_filters( 'woo_cao_statustocancel', array( 'on-hold' ) );

if ( $default_status && is_array( $default_status ) ) {
foreach ( $default_status as $status ) {
if ( in_array( $status, $woo_status_authorized ) ) {
$woo_status[] = sprintf( 'wc-%s', $status );
}
}
}

if ( empty( $woo_status ) ) {
$woo_status[] = 'wc-on-hold';
}

$woo_status = implode( "','", $woo_status );

return $woo_status;
}

/**
* Will check and store the products of the canceled order.
*
* @param int $order_id order ID.
*/
private function restock( $order_id ) {

$order = new \WC_Order( $order_id );
$order = new WC_Order( $order_id );

$line_items = $order->get_items();

Expand Down
12 changes: 9 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: woocommerce, cancel, order, pending, on hold, gateway
Requires PHP: 7.0
Requires at least: 4.0
Tested up to: 5.2
Stable tag: 1.5.1
Stable tag: 1.6.0
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -19,8 +19,6 @@ If you have check or transfer type orders for example, you will be able to set a

WooCommerce Cancel Abandoned Order, will take care of checking this and change the status of the order to "Cancel" if you have not received payment on time.

Since version **1.4.0** it's possible to cancel orders in hours ... Yeah!

[**GitHub**](https://github.com/rvola/woo-cancel-abandoned-order) | [**Donate**](https://www.paypal.me/rvola)

== Installation ==
Expand Down Expand Up @@ -51,6 +49,7 @@ _Filters_
* **woo_cao_date_order** ($old_date, $gateway, $mode) : Change the calculation date for pending orders.
* **woo_cao_default_hours** : Default value of the number of hours for order processing.
* **woo_cao_default_days** : Default value of the number of days for order processing.
* **woo_cao_statustocancel** ($status) : Allows you to add or change which WooCommerce order status the plugin should cancel.


== Wiki ==
Expand All @@ -75,12 +74,19 @@ Mode **"Daily"**: every day at 0:00

If you checked the box to enable this feature in the gateway, the system will restock each product line of the abandoned order.

= I would like to cancel orders pending payment =
Follow the [tutorial here](https://github.com/rvola/woo-cancel-abandoned-order/wiki/Change-the-status-type-for-the-cancellation-process) to change the status of orders to cancel. By default the "on-hold" commands are canceled.

= I want to make suggestions =
We’re glad you want to help us improve **WooCommerce Cancel Abandoned Order**!
The GIT repository is available here [https://github.com/rvola/woo-cancel-abandoned-order](https://github.com/rvola/woo-cancel-abandoned-order)

== Changelog ==

= 1.6.0 / 2019-05-07 =
* NEW / Order status hook for the cancel process.
* MINOR / code style call Class external.

= 1.5.1 / 2019-04-03 =
* ✔︎ Compatibility WP 5.2
* ✔︎ Compatibility WOO 3.6
Expand Down
6 changes: 3 additions & 3 deletions woo-cancel-abandoned-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Description: Cancel "on hold" orders after a certain number of days or by hours
Version: 1.5.1
Revision: 2019-04-03
Version: 1.6.0
Revision: 2019-05-07
Creation: 2017-10-28
Author: studio RVOLA
Expand All @@ -32,7 +32,7 @@
}

define( 'WOOCAO_FILE', __FILE__ );
define( 'WOOCAO_VERSION', '1.5.1' );
define( 'WOOCAO_VERSION', '1.6.0' );

include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
Expand Down

0 comments on commit 418e4ed

Please sign in to comment.