WooCommerce Intro
WooCommerce is the e-commerce plugin on top of WordPress: products, carts, orders, payment gateways, shipping zones, taxes. The right architecture choices early (custom product types, tax handling, headless or not) decide how much rope WooCommerce gives you for free vs how much custom code you write.
A working Woo stack: products, payments, hooks
EXAMPLE
# 1) Install + activate
wp plugin install woocommerce --activate
wp wc setup # walks through store address, currency, tax basics
# 2) Create a product programmatically
wp wc product create \
--name='Wool jacket' --type=simple --regular_price=199.00 \
--stock_quantity=12 --manage_stock=1 \
--categories='[{"id":15}]' --user=1
# 3) The four product types you usually need
# - simple: one SKU, one price; the default
# - variable: size/colour variants; each variant has its own SKU + stock
# - grouped: bundles of simple products (not the same as a multi-pack)
# - external: affiliate-link products (redirect to an external store)
# 4) Payment gateways — pick by region + risk profile
# - Stripe + Apple/Google Pay: global, low integration cost
# - PayPal Checkout: broad reach
# - Klarna / Afterpay: BNPL options popular in AU/EU
# - Cash on delivery / bank xfer for B2B
# Each is a plugin. Test in sandbox / sandbox mode BEFORE switching to live.
# 5) Shipping zones — set per region (e.g. AU domestic vs international)
# Settings -> Shipping -> Add zone -> Add a method (flat rate, free, table rates)
# 6) Tax handling — the messy part
# AU GST 10% inclusive: Settings -> General -> 'prices include tax: YES'
# Settings -> Tax -> set standard rates by country
# Always test the cart with a few products vs different ship-to countries.
# 7) Hooks you will use 80% of the time
# functions.php or a tiny plugin
# Modify the product price in the cart
add_filter('woocommerce_get_price_html', function ($price, $product) {
if (is_user_logged_in() && current_user_can('view_b2b_prices')) {
return wc_price($product->get_meta('b2b_price') ?: $product->get_price());
}
return $price;
}, 10, 2);
# Fire on a paid order
add_action('woocommerce_order_status_processing', function ($order_id) {
$order = wc_get_order($order_id);
// post to inventory system, send to fulfilment, etc.
});
# Block guest checkout if the cart total > X (B2B-only)
add_filter('woocommerce_checkout_must_login', function ($must) {
return WC()->cart && WC()->cart->total > 500 ? true : $must;
});
# Add a custom checkout field
add_filter('woocommerce_checkout_fields', function ($fields) {
$fields['billing']['billing_abn'] = [
'label' => 'ABN', 'required' => false, 'class' => ['form-row-wide'],
];
return $fields;
});
# 8) Stock + reservations
# Settings -> Products -> Inventory -> 'Hold stock (minutes)' for unpaid orders
# Hooks for low stock alerts: woocommerce_low_stock_notification
# 9) Headless WooCommerce
# The Store API ships JWT-authenticated REST endpoints for products / cart / checkout.
# Use it from Next.js / Astro front ends:
fetch('https://shop.example.com/wp-json/wc/store/v1/products?per_page=20')
# For session-bound endpoints (cart / checkout), pass Cart-Token header.
# 10) Performance
# - Object cache (Redis) is the single biggest win for Woo
# - Object Cache Pro + Memcached Redis for heavy stores
# - Disable WooCommerce on pages where it does not need to load (Asset CleanUp)
# - Lazy-load product images, generate WebP/AVIF
# - Cache full pages (Cache Everything via Cloudflare with bypass on cart / checkout cookies)
# 11) Backups
# Woo writes constantly (carts, sessions, orders). Backup the DB at least nightly,
# AND ALWAYS BEFORE a major plugin update.
# 12) Common pitfalls
# - Updating to a major Woo version without staging first: every release deprecates hooks
# - Mixing tax-inclusive and tax-exclusive prices in product data
# - 'Simple' products with multiple options jammed into a single SKU
# - Shipping methods configured but not assigned to a zone (silent 'no methods available')
Why it matters
Always do major Woo upgrades on a staging clone first. Even point releases have changed checkout templates and broken custom themes; on production, the same migration takes the store offline for an unpredictable window. A 20-minute clone-and-test before the live update saves a 4-hour incident.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
// WooCommerce — turns WP into a storefront. // Products, cart, checkout, orders, shipping, taxes.Try it Yourself »
Discussion
Loading…