Notes: Add filters to disable milestone and sales record notes. (https://github.com/woocommerce/woocommerce-admin/pull/2227)

* Add filters to disable milestone and sales record notes.

* Updates per feedback.
This commit is contained in:
Timmy Crawford 2019-06-11 08:12:16 -07:00 committed by GitHub
parent 5d01cee56c
commit 39d5c09c81
2 changed files with 41 additions and 0 deletions

View File

@ -39,6 +39,19 @@ class WC_Admin_Notes_New_Sales_Record {
* Possibly add a sales record note.
*/
public static function possibly_add_sales_record_note() {
/**
* Filter to allow for disabling sales record milestones.
*
* @since 3.7.0
*
* @param boolean default true
*/
$sales_record_notes_enabled = apply_filters( 'woocommerce_admin_sales_record_milestone_enabled', true );
if ( ! $sales_record_notes_enabled ) {
return;
}
$yesterday = date( 'Y-m-d', current_time( 'timestamp', 0 ) - DAY_IN_SECONDS );
$total = self::sum_sales_for_date( $yesterday );

View File

@ -124,6 +124,11 @@ class WC_Admin_Notes_Order_Milestones {
* Used to avoid celebrating milestones that were reached before plugin activation.
*/
public function backfill_last_milestone() {
// If the milestone notes have been disabled via filter, bail.
if ( ! $this->are_milestones_enabled() ) {
return;
}
$this->set_last_milestone( $this->get_current_milestone() );
}
@ -262,10 +267,33 @@ class WC_Admin_Notes_Order_Milestones {
}
}
/**
* Convenience method to see if the milestone notes are enabled.
*
* @return boolean True if milestone notifications are enabled.
*/
public function are_milestones_enabled() {
/**
* Filter to allow for disabling order milestones.
*
* @since 3.7.0
*
* @param boolean default true
*/
$milestone_notes_enabled = apply_filters( 'woocommerce_admin_order_milestones_enabled', true );
return $milestone_notes_enabled;
}
/**
* Add milestone notes for other significant thresholds.
*/
public function other_milestones() {
// If the milestone notes have been disabled via filter, bail.
if ( ! $this->are_milestones_enabled() ) {
return;
}
$last_milestone = $this->get_last_milestone();
$current_milestone = $this->get_current_milestone();