WooCommerce Snippets for Sublime Text

WooCommerce Snippets is a free Sublime Text package with 172 WooCommerce snippets for PHP developers. Each one expands into a complete, working code pattern: a hook with the right callback signature, an order query that is safe for High-Performance Order Storage (HPOS), or a full shipping method scaffold. You type wc:, pick a pattern, and press Tab.

The WooCommerce code snippets in this package were written against the WooCommerce 10.5.2 source. So they use the current APIs: HPOS, Block Checkout, the Store API and Action Scheduler.

What is in the 172 WooCommerce snippets

Category Snippets Prefix What it covers
Action hooks 32 wc:action: add_action() calls with the correct callback signature
Filter hooks 30 wc:filter: add_filter() calls with return values
CRUD 15 wc:get: wc:create: wc:update: Orders, products, customers and coupons
Queries 10 wc:query: wc_get_orders(), WC_Product_Query and meta queries
Cart 8 wc:cart: Items, totals, fees, sessions and coupons
Checkout 8 wc:checkout: Fields, validation, gateways and redirects
REST API 8 wc:rest: Endpoints, schemas and webhooks
Conditionals 12 wc:is: is_shop(), is_product(), is_checkout() and more
Admin 8 wc:admin: Settings pages, product tabs and meta boxes
Emails 5 wc:email: Custom email class, triggers and templates
HPOS 6 wc:hpos: High-Performance Order Storage patterns
Templates 6 wc:template: Overrides, hooks and template parts
Shipping 6 wc:shipping: Custom methods, zones and rates
Action Scheduler 4 wc:scheduler: Background tasks and recurring jobs
Blocks and Store API 5 wc:blocks: Block checkout fields and Store API extensions
Notices 5 wc:notice: wc:log: Storefront notices and the WooCommerce logger
Security 4 wc:nonce: wc:cap: wc:sanitize: Nonces, capabilities and validation

A few examples

Type this You get
wc:filter:checkout_fields A filter that changes the checkout fields
wc:order:items A loop through the items of an order
wc:is:hpos A check for whether HPOS is enabled
wc:shipping:register The registration of a custom shipping method
wc:scheduler:recurring A recurring background action with Action Scheduler
wc:blocks:checkout_field A custom field for the block checkout
wc:admin:settings_page The scaffold of a WooCommerce settings page

How the snippets work

  1. Open a PHP file in Sublime Text.
  2. Type wc:. The autocomplete panel lists every snippet.
  3. Keep typing to narrow the list. For example, wc:checkout: shows only checkout patterns.
  4. Press Tab or Enter to expand the snippet.
  5. Press Tab again to jump from one placeholder to the next.

Every placeholder has a sensible default, so a snippet works even if you change nothing. The first tab stop is always the value you are most likely to edit, such as the hook or field name.

Two snippets wrap code you have selected: wc:wrap:action puts it inside add_action(), and wc:wrap:filter inside add_filter(). Select the code, then run the snippet from the Command Palette.

Install it

  1. Open the Command Palette: Cmd+Shift+P on a Mac, Ctrl+Shift+P on Windows and Linux.
  2. Choose Package Control: Install Package.
  3. Search for WooCommerce and press Enter.

To install by hand, download the latest release from GitHub and extract it into your Sublime Text Packages folder.

Compatibility

  • Sublime Text: 3 and 4.
  • WooCommerce: built from and tested against 10.5.2.
  • PHP: 7.4 and later.

The patterns use the WC_Data API and HPOS-safe methods. Legacy patterns, such as update_post_meta for orders, are left out on purpose. The package also includes patterns for WooCommerce Blocks, WooCommerce Subscriptions queries and REST API v3.

Common questions

Why do the snippets not expand when I press Tab?

Check your word_separators setting. If it contains a colon, Sublime Text splits the trigger at each colon. Remove the colon from that setting and the snippets expand.

Why do the snippets not show up in my template file?

They are scoped to PHP. They appear inside PHP tags, not in the HTML parts of a template file.

Do they work with High-Performance Order Storage?

Yes. Every order pattern uses HPOS-safe methods, and six snippets cover HPOS itself, including a check for whether it is enabled.

I see old completions from another package. What should I do?

If you have the older WooCommerce Autocomplete package installed, remove it first. Its trigger names conflict with this package.

Is it free?

Yes. It is open source under the MIT license.

Related

For Vercel and Next.js work, see Vercel Snippets for Sublime Text. The rest of my work is on the open source contributions page.