Automattic\WooCommerce\Internal\Admin\Notes

NewSalesRecord::possibly_add_note()public staticWC 1.0

Possibly add a sales record note.

Method of the class: NewSalesRecord{}

Return

null. Nothing.

Usage

$result = NewSalesRecord::possibly_add_note();

NewSalesRecord::possibly_add_note() code WC 7.1.0

public static function possibly_add_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 = gmdate( 'Y-m-d', current_time( 'timestamp', 0 ) - DAY_IN_SECONDS );
	$total     = self::sum_sales_for_date( $yesterday );

	// No sales yesterday? Bail.
	if ( 0 >= $total ) {
		return;
	}

	$record_date = get_option( self::RECORD_DATE_OPTION_KEY, '' );
	$record_amt  = floatval( get_option( self::RECORD_AMOUNT_OPTION_KEY, 0 ) );

	// No previous entry? Just enter what we have and return without generating a note.
	if ( empty( $record_date ) ) {
		update_option( self::RECORD_DATE_OPTION_KEY, $yesterday );
		update_option( self::RECORD_AMOUNT_OPTION_KEY, $total );
			return;
	}

	// Otherwise, if yesterdays total bested the record, update AND generate a note.
	if ( $total > $record_amt ) {
		update_option( self::RECORD_DATE_OPTION_KEY, $yesterday );
		update_option( self::RECORD_AMOUNT_OPTION_KEY, $total );

		// We only want one sales record note at any time in the inbox, so we delete any other first.
		Notes::delete_notes_with_name( self::NOTE_NAME );

		$note = self::get_note_with_record_data( $record_date, $record_amt, $yesterday, $total );
		$note->save();
	}
}