diff --git a/CHANGELOG.md b/CHANGELOG.md index 7566e51..f24edae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 3607d4d..9f83050 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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) @@ -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) diff --git a/includes/class-cao.php b/includes/class-cao.php index a47f0da..7c60dde 100644 --- a/includes/class-cao.php +++ b/includes/class-cao.php @@ -7,6 +7,8 @@ namespace RVOLA\WOO\CAO; +use WC_Order; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -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( " @@ -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 @@ -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', @@ -163,6 +168,36 @@ 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. * @@ -170,7 +205,7 @@ private function cancel_order( $order_id ) { */ private function restock( $order_id ) { - $order = new \WC_Order( $order_id ); + $order = new WC_Order( $order_id ); $line_items = $order->get_items(); diff --git a/readme.txt b/readme.txt index ede949b..24d9b75 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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 == @@ -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 == @@ -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 diff --git a/woo-cancel-abandoned-order.php b/woo-cancel-abandoned-order.php index c28ba16..3b092fe 100644 --- a/woo-cancel-abandoned-order.php +++ b/woo-cancel-abandoned-order.php @@ -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 @@ -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' ) ) {