Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.3.0 #44

Merged
merged 37 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
904cf54
Fix example code for defining custom intervals
stevegrunwell May 19, 2020
87bbc36
Add missing plugin headers
stevegrunwell May 19, 2020
ccb41d1
Merge pull request #32 from nexcess/fix/add-missing-plugin-headers
bswatson May 19, 2020
9517565
Merge pull request #31 from nexcess/docs/fix-custom-interval-example
bswatson May 19, 2020
07a6eaf
Update the PHPUnit bootstrap file to work with WooCommerce 4.2
stevegrunwell Jun 10, 2020
726dfe8
Add WooCommerce 4.2 to the testing matrix
stevegrunwell Jun 10, 2020
38289ed
Merge pull request #33 from nexcess/feature/woocommerce-4.2-testing
bswatson Jun 10, 2020
6a33768
Push readme and/or asset changes to WordPress.org automatically
stevegrunwell Jun 17, 2020
b0f8ad6
Merge pull request #34 from nexcess/feature/update-wordpress-org-assets
bswatson Jun 18, 2020
df92feb
Clear the limiter transient if the limiter settings are changed
stevegrunwell Jun 26, 2020
1191707
Add a new OrderLimiter::has_orders_in_current_interval() method
stevegrunwell Jun 26, 2020
1e6fba8
Introduce a new TestCase and move the generate_order() method into th…
stevegrunwell Jun 26, 2020
d7bf39f
Speed up the test suite by lowering the default posts_per_page value …
stevegrunwell Jun 26, 2020
e77827b
Display a notice on the settings screen if orders have already been p…
stevegrunwell Jun 26, 2020
c163dd4
Add a note to the README regarding settings taking effect immediately
stevegrunwell Jun 26, 2020
b3a2410
Use WordPress 5.3 in the "Minimum Requirements" CI job
stevegrunwell Jun 26, 2020
5a6e045
Bump the minimum WP version in the README.md file
stevegrunwell Jun 26, 2020
ee7ce5c
Add links to custom interval gists
stevegrunwell Jun 26, 2020
069dee2
Merge pull request #39 from nexcess/docs/example-custom-intervals
bswatson Jun 26, 2020
5c76026
Merge pull request #38 from nexcess/fix/minimum-requirements-travis
bswatson Jun 26, 2020
db91051
Merge pull request #37 from nexcess/feature/clear-transient-on-settin…
bswatson Jun 26, 2020
cbc610e
Introduce a new limit_orders_pre_get_remaining_orders filter
stevegrunwell Jul 15, 2020
d3235c2
Add the limit_orders_pre_count_qualifying_orders filter
stevegrunwell Jul 15, 2020
2c1a952
Document the 'limit_orders_pre_count_qualifying_orders' and 'limit_or…
stevegrunwell Jul 15, 2020
e2a2d9a
Register a "Reset Order Limiting" WooCommerce tool
stevegrunwell Jul 15, 2020
1c04ea6
Separate reset_limiter() into reset() and reset_limiter_on_update()
stevegrunwell Jul 15, 2020
bbe0cb9
Merge pull request #42 from nexcess/feature/reset-button
bswatson Jul 15, 2020
2a1cae9
Merge pull request #41 from nexcess/feature/limiter-filters
bswatson Jul 15, 2020
9659763
Bump the "WC tested up to" to version 4.3
stevegrunwell Jul 16, 2020
c8273cb
Add two new FAQs to the WordPress.org readme.txt file
stevegrunwell Jul 16, 2020
de71629
Changelog updates for version 1.3.0
stevegrunwell Jul 16, 2020
f0a5533
Version bump to 1.3.0
stevegrunwell Jul 16, 2020
1f2e18c
Use assertContains() instead of assertStringContainsString()
stevegrunwell Jul 16, 2020
6b0018c
Merge pull request #45 from nexcess/fix/phpunit-6.x-compat
bswatson Jul 16, 2020
cd6ab89
Merge pull request #43 from nexcess/feature/verify-wc-43-compat
bswatson Jul 16, 2020
ee27c2e
Merge branch 'develop' into release/v1.3.0
stevegrunwell Jul 16, 2020
e0fdbf6
Generate the order after initializing the plugin in a_notice_should_b…
stevegrunwell Jul 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[{.jshintrc,*.json,*.yml}]
[{.jshintrc,*.json}]
indent_style = space
indent_size = 4

[*.yml]
indent_style = space
indent_size = 2

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
18 changes: 18 additions & 0 deletions .github/workflows/update-wordpress-org-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Update assets on WordPress.org

on:
push:
branches:
- master

jobs:
master:
name: Send to WordPress.org
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Push readme.txt and/or asset changes
uses: 10up/action-wordpress-plugin-asset-update@master
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ php:
- 7.1
- 7.0

# To keep the test matrix from exploding over time, we'll actively test against the latest three
# releases, then cherry-pick what to test across older ones.
env:
- WP_VERSION=5.3 WC_VERSION=4.1
- WP_VERSION=5.3 WC_VERSION=4.0
- WP_VERSION=5.3 WC_VERSION=3.9.3
- WP_VERSION=latest WC_VERSION=4.3
- WP_VERSION=latest WC_VERSION=4.2
- WP_VERSION=latest WC_VERSION=4.1
- WP_VERSION=latest WC_VERSION=3.9.3

matrix:
fast_finish: true
Expand All @@ -34,6 +37,9 @@ matrix:
- name: Static Code Analysis
php: 7.3
env: WP_TRAVISCI=phpstan
- name: Minimum requirements
php: 7.0
env: WP_VERSION=5.3 WC_VERSION=3.9.3
- name: Bleeding Edge
php: 7.4
env: WP_VERSION=trunk WC_VERSION=latest
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Version 1.3.0] — 2020-07-16

### Added

* Add a new "Reset order limiting" tool to WooCommerce › Status › Tools ([#42])
* Introduce new filters — `limit_orders_pre_count_qualifying_orders` and `limit_orders_pre_get_remaining_orders` — for customizing the logic around counting qualifying and remaining orders, respectively ([#41])
* Automatically clear the cached order count when settings are changed or when WooCommerce order transients are cleared ([#37], [#42])

### Updated

* Bump "WC tested up to" to 4.3 ([#43]).

### Fixed

* Added missing plugin headers ([#32])


## [Version 1.2.1] — 2020-05-08

### Updated
Expand Down Expand Up @@ -67,6 +84,7 @@ Initial plugin release.
[Version 1.1.2]: https://github.com/nexcess/limit-orders/releases/tag/v1.1.2
[Version 1.2.0]: https://github.com/nexcess/limit-orders/releases/tag/v1.2.0
[Version 1.2.1]: https://github.com/nexcess/limit-orders/releases/tag/v1.2.1
[Version 1.3.0]: https://github.com/nexcess/limit-orders/releases/tag/v1.3.0
[#5]: https://github.com/nexcess/limit-orders/pull/5
[#6]: https://github.com/nexcess/limit-orders/pull/6
[#8]: https://github.com/nexcess/limit-orders/pull/8
Expand All @@ -77,3 +95,8 @@ Initial plugin release.
[#23]: https://github.com/nexcess/limit-orders/pull/23
[#26]: https://github.com/nexcess/limit-orders/pull/26
[#28]: https://github.com/nexcess/limit-orders/issues/28
[#32]: https://github.com/nexcess/limit-orders/pull/32
[#37]: https://github.com/nexcess/limit-orders/pull/37
[#41]: https://github.com/nexcess/limit-orders/pull/41
[#42]: https://github.com/nexcess/limit-orders/pull/42
[#43]: https://github.com/nexcess/limit-orders/pull/43
91 changes: 88 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Limit Orders for WooCommerce lets you limit the number of orders your store will

## Requirements

* WordPress 5.2 or newer
* WordPress 5.3 or newer
* WooCommerce 3.9 or newer
* PHP 7.0 or newer

Expand All @@ -27,6 +27,16 @@ Configuration for Limit Orders for WooCommerce is available through WooCommerce

![The settings screen for Limit Orders for WooCommerce](.wordpress-org/screenshot-1.png)

⚠️ **Please be aware** that any changes made to the settings will take effect immediately.

For example, if you're using an hourly interval and switch it to daily, the plugin will re-calculate whether or not to disable ordering based on the number of orders received since the start of the current day (midnight, by default).

If you need to clear the cached order count, you may do so via WooCommerce › Status › Tools › Reset Order Limiting within WP Admin.

### General settings

These settings determine how and when order limiting should take effect.

<dl>
<dt>Enable Order Limiting</dt>
<dd>Check this box to enable order limiting.</dd>
Expand Down Expand Up @@ -96,6 +106,11 @@ The plugin includes a few intervals by default:

If your store needs a custom interval, you may add them using filters built into the plugin.

You may also use these gists, which define custom plugins that can be run alongside Limit Orders:

* [Limit Orders for WooCommerce - 15min Intervals](https://gist.github.com/stevegrunwell/ab8a7a2036f993c3c09c6504acda96eb)
* [Limit Orders for WooCommerce - Never-ending Interval](https://gist.github.com/stevegrunwell/f9cc978cd5c23f744142798b7b772ba6)

#### Example: Reset Limits Annually

Let's say your store can only accept a certain number of orders in a year.
Expand All @@ -112,7 +127,7 @@ You may accomplish this by adding the following code into your theme's `function
*/

/**
* Add "fortnightly" to the list of intervals.
* Add "Annually" to the list of intervals.
*
* @param array $intervals Available time intervals.
*
Expand Down Expand Up @@ -160,7 +175,7 @@ add_filter( 'limit_orders_interval_start', function ( $start, $interval ) {
* current $interval is not "annually".
*/
add_filter( 'limit_orders_next_interval', function ( $start, $current, $interval ) {
if ( 'annually' !== 'interval' ) {
if ( 'annually' !== $interval ) {
return $start;
}

Expand Down Expand Up @@ -192,3 +207,73 @@ add_filter( 'limit_orders_message_placeholders', function ( $placeholders ) {
Now, we can create customer-facing notices like:

> {store_name} is a little overwhelmed right now, but we'll be able to take more orders on {next_interval:date}. Please check back then!

### Dynamically changing limiter behavior

In certain cases, you may want to further customize the logic around _which_ orders count toward the limit or, for example, change the behavior based on time of day. Limit Orders for WooCommerce has you covered:

#### Customize the counting of qualified orders

Sometimes, you only want to limit certain types of orders. Maybe some orders are fulfilled via third parties (e.g. [dropshipping](https://www.liquidweb.com/woocommerce-resource/dropshipping-glossary/)), or perhaps you're willing to bend the limits a bit for orders that contain certain products.

You can customize the logic used to calculate the count via the `limit_orders_pre_count_qualifying_orders` filter:

```php
/**
* Determine how many orders to count against the current interval.
*
* @param bool $preempt Whether the counting logic should be preempted. Returning
* anything but FALSE will bypass the default logic.
* @param OrderLimiter $limiter The current OrderLimiter instance.
*
* @return int The number of orders that should be counted against the limit.
*/
add_filter( 'limit_orders_pre_count_qualifying_orders', function ( $preempt, $limiter ) {
/*
* Do whatever you need to do here to count how many orders count.
*
* Pay close attention to date ranges here, and check out the public methods
* on the Nexcess\LimitOrders\OrderLimiter class.
*/
}, 10, 2 );
```

Please note that the `LimitOrders::count_qualifying_orders()` method (where this filter is defined) is only called in two situations:

1. When a new order is created.
2. If the `limit_orders_order_count` transient disappears.

#### Dynamically change the order limit

If, for example, you want to automatically turn off the store overnight, you might do so by setting the limit to `0` only during certain hours.

You can accomplish this using the `limit_orders_pre_get_remaining_orders` filter:

```php
/**
* Disable the store between 10pm and 8am.
*
* This works by setting the limit on Limit Orders for WooCommerce to zero if
* the current time is between those hours.
*
* @param bool $preempt Whether or not the default logic should be preempted.
* Returning anything besides FALSE will be treated as the
* number of remaining orders that can be accepted.
*
* @return int|bool Either 0 if the store is closed (meaning zero orders remaining)
* or the value of $preempt if Limit Orders should proceed normally.
*/
add_filter( 'limit_orders_pre_get_remaining_orders', function ( $preempt ) {
$open = new \DateTime('08:00', wp_timezone());
$close = new \DateTime('22:00', wp_timezone());
$now = current_datetime();

// We're currently inside normal business hours.
if ( $now >= $open && $now < $close ) {
return $preempt;
}

// If we've gotten this far, turn off ordering.
return 0;
} );
```
21 changes: 13 additions & 8 deletions limit-orders.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php
/**
* Plugin Name: Limit Orders for WooCommerce
* Description: Automatically disable WooCommerce's checkout process after reaching a maximum number of orders.
* Author: Nexcess
* Author URI: https://nexcess.net
* Text Domain: limit-orders
* Domain Path: /languages
* Version: 1.2.1
* Plugin Name: Limit Orders for WooCommerce
* Plugin URI: https://wordpress.org/plugins/limit-orders/
* Description: Automatically disable WooCommerce's checkout process after reaching a maximum number of orders.
* Version: 1.3.0
* Requires at least: 5.3
* Requires PHP: 7.0
* License: MIT
* License URI: https://github.com/nexcess/limit-orders/blob/develop/LICENSE.txt
* Author: Nexcess
* Author URI: https://nexcess.net
* Text Domain: limit-orders
* Domain Path: /languages
*
* WC requires at least: 3.9
* WC tested up to: 4.1
* WC tested up to: 4.3
*
* @package Nexcess\LimitOrders
*/
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">./tests/</directory>
<exclude>./tests/SampleTest.php</exclude>
</testsuite>
</testsuites>
<filter>
Expand Down
20 changes: 19 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: WooCommerce, ordering, limits, throttle
Requires at least: 5.3
Tested up to: 5.4
Requires PHP: 7.0
Stable tag: 1.2.1
Stable tag: 1.3.0
License: MIT
License URI: https://github.com/nexcess/limit-orders/blob/master/LICENSE.txt

Expand Down Expand Up @@ -36,6 +36,18 @@ Meanwhile, a fully-customizable message will be displayed on all WooCommerce sho

Yes, the order creation process through WP Admin is unaffected.

= Can the plugin limit orders based on some custom time interval? =

The base plugin defines several common intervals: hourly, daily, weekly, and monthly.

In the event that you require a custom interval, they may be registered with a few filters. [Several examples are available in the plugin's GitHub repository](https://github.com/nexcess/limit-orders#adding-custom-intervals).

= Can the plugin limit orders based on category/amount/items/etc.? =

The plugin is designed to work based on the total number of orders, but as of version 1.3.0 filters have been introduced that enable developers to specify which orders should be counted against the limit.

[Documentation for these filters is available in the plugin's GitHub repository](https://github.com/nexcess/limit-orders#customizing-plugin-behavior).

== Screenshots ==

1. The settings screen for Limit Orders for WooCommerce
Expand All @@ -45,6 +57,12 @@ Yes, the order creation process through WP Admin is unaffected.

For a complete list of changes, please [see the plugin's changelog on GitHub](https://github.com/nexcess/limit-orders/blob/master/CHANGELOG.md).

= 1.3.0 (2020-07-16) =
* Added new "Reset order limiting" WooCommerce tool.
* Introduce new filters for customizing order counting logic.
* Automatically clear the cached order count when settings are updated or WooCommerce order transients are cleared.
* Verify compatibility with WooCommerce 4.3.

= 1.2.1 (2020-05-08) =
* Verify compatibility with WooCommerce 4.1.

Expand Down
27 changes: 27 additions & 0 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function init() {
add_filter( 'woocommerce_get_settings_pages', [ $this, 'register_settings_page' ] );
add_filter( 'admin_notices', [ $this, 'admin_notice' ] );
add_filter( 'plugin_action_links_' . $basename, [ $this, 'action_links' ] );
add_filter( 'woocommerce_debug_tools', [ $this, 'debug_tools' ] );
add_action( 'woocommerce_delete_shop_order_transients', [ $this, 'reset_limiter' ] );
add_action( 'woocommerce_system_status_report', [ $this, 'system_status_report' ] );
}

Expand Down Expand Up @@ -112,6 +114,31 @@ public function system_status_report() {
] );
}

/**
* Add additional debugging tools.
*
* @param array $tools Currently-registered tools.
*
* @return array The $tools array with our button included.
*/
public function debug_tools( $tools ) {
$tools['limit_orders'] = [
'name' => __( 'Reset order limiting', 'limit-orders' ),
'button' => __( 'Reset limiter', 'limit-orders' ),
'desc' => __( 'Clear the cached order count. This may be needed if you\'ve changed your order limiting settings.', 'limit-orders' ),
'callback' => [ $this, 'reset_limiter' ],
];

return $tools;
}

/**
* Delete the order limiter transient.
*/
public function reset_limiter() {
$this->limiter->reset();
}

/**
* Retrieve a link to the plugin's settings page.
*
Expand Down
Loading