Skip to content

Instantly share code, notes, and snippets.

@danielmorell
Last active July 7, 2020 17:37
Show Gist options
  • Save danielmorell/2af450a7b41d39070799c3e3f83b7d17 to your computer and use it in GitHub Desktop.
Save danielmorell/2af450a7b41d39070799c3e3f83b7d17 to your computer and use it in GitHub Desktop.
Custom Order Numbers Plugin Project

Custom Order Numbers Plugin Project

This is a take home project so we can get an idea of your code skills and style.

This project should take between 2-3 hours and should be completed within a week.

The Problem

By default, WooCommerce uses the WordPress post ID as the order number. We run several eCommerce websites for separate business units e.g. Custom Cages and Custom Aquariums. We need each order number to be unique.

We also need the order number to provide some contextual information about the order. This is helpful for reporting in our sales and accounting software.

Order Number Constraints and Format

The following constraints are documented here for reference latter, so we can look back on the reasons we made the decisions we did.

  • QuickBooks will only accept order numbers that are 11 characters or less.
  • Order numbers must indicate the business unit.
  • Order numbers must indicate if the customer is a reseller.
  • Order numbers must show the year and month the order was created.
  • Order numbers must be unique. They cannot overlap with existing order numbers.

To satisfy all of these requirements the following format will be used for orders created by WooCommerce.

BYYMM-T0000
  1. B is a single character that represents the business unit. C = Custom Cages, A = Custom Aquariums, V = Vision Products, S = Serenity. Example C for Custom Cages.
  2. YY is the two-digit representation of the year the order is placed. Example 20 for the year 2020.
  3. MM is the two-digit, zero padded representation of the month the order is placed. Example 07 for July.
  4. T is the single character representation of the customer type. C for a standard customer, and R for a reseller.
  5. 0000 is the zero padded, single incremented, sequential order number. This number resets to 0 each month. This number does not need to be unique across business units, since the business unit is indicated by the first character of the order number. Example 0093 would be the 93rd order created that month.

Examples:

The first order of July 2020 on Custom aquariums for a reseller, would be A2007-R0001.

The twentieth order of November 2021 on Vision Products for a standard customer would be V2111-C0020.

The Solution

To make this work across all our WooCommerce stores we want to create a plugin that replaces the default WooCommerce order number with our custom order number.

Your job is to write the core of that plugin. You have the liberty to create it as you wish. However, the following requirements must be met for the plugin to be considered operable.

  1. The WC_Order->get_order_number() method must return the custom order number.
  2. Order numbers must adhere to the above format.
  3. Each order number must be unique.

Things You Can Assume to be True

  1. There are no existing orders that need to be updated.
  2. A new user role reseller.
  3. The website uses the latest version of WordPress and WooCommerce.

How to Submit Your Solution

  1. Create your own repo public or private and build your plugin in that repository.
  2. Notify us in some manner (GitHub invite / email / phone / carrier pigeon) of your repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment