WooCommerce Development for Middle Devs: PHP and Gutenberg

90

questions

WooCommerce as a System

How do you check in code whether HPOS is enabled?

AutomatticWooCommerceUtilitiesOrderUtil::custom_orders_table_usage_is_enabled().

How do you react to any order save?

The woocommerce_after_order_object_save hook — it fires no matter where the order was saved from: admin, REST, checkout, CLI.

What is a data store in WooCommerce?

A class responsible for saving and reading a specific object type. The CRUD object doesn't know where its data lives. That's why HPOS could be introduced without changing the public API: only the order data store changed.

What is sync mode?

During the transition WooCommerce writes orders to both storages. You can roll back, and old plugins that read wp_posts still get data. After the transition sync is turned off because it doubles every write.

What is wc_product_meta_lookup and why does it exist?

A denormalized table with a product's price, stock, SKU and rating. WooCommerce uses it for sorting and filters to avoid slow JOINs on wp_postmeta.

Where is a guest customer's cart stored?

In the woocommerce_sessions table. The cookie holds only the session key. For a logged-in user the cart is also saved in user meta so it can be restored on another device.

Why does WooCommerce have its own Action Scheduler queue?

WP-Cron depends on site visits and has no statuses or retries. Action Scheduler stores jobs in the database, runs them in batches and logs errors. Webhooks, analytics, some emails and migrations run on it.

Why is HPOS faster?

Orders get their own tables with the needed columns and indexes (status, date, customer, total). No thousands of wp_postmeta rows per order and no heavy JOINs. Order search and reports don't compete with posts and pages.

Why is wc_get_products() better than WP_Query?

It takes parameters in WooCommerce terms (price, stock_status, sku, visibility), builds the query itself and returns WC_Product objects. The code doesn't depend on how the data is laid out in tables.

Hooks and Extensions

Do PHP overrides work in a block theme?

Not for the parts rendered by blocks: a block has its own render. Some blocks (for example, the classic Legacy Template) still use PHP templates, but the main path is blocks.

How do you find the priority WooCommerce used to add a function?

Look in includes/wc-template-hooks.php, in Query Monitor → Hooks, or dump $wp_filter['hook_name'].

What does Requires Plugins do?

A plugin header since WordPress 6.5. Core won't activate the plugin until its dependencies are active, and won't deactivate a dependency while a dependent plugin is active.

What is a dynamic hook? Give an example.

A hook whose name contains a variable part. For example, woocommerce_order_status_completed or woocommerce_product_get_price — WooCommerce builds them from a status or property name.

What is the difference between an action and a filter?

An action does something at a given moment and returns nothing. A filter receives a value, changes it and must return it. Technically both run on the same WP_Hook system.

What should a client choose: a block or a classic theme?

It depends on the project. A block theme gives code-free editing of store templates and the modern checkout. A classic one fits when many extensions depend on PHP templates and checkout hooks. Back the decision with a plugin audit.

Where does WooCommerce show the theme's outdated templates?

WooCommerce → Status → System status, the Templates section. It shows the copy's version and the core version.

Which hook do you declare compatibility on, and why?

before_woocommerce_init: WooCommerce collects declarations before it initializes features. A later declaration is ignored.

Why WC tested up to?

WooCommerce shows a warning in the plugin list if the WooCommerce version is newer than the tested one. It's a signal for the admin before updating.

Product Catalog

How do you find a product by SKU?

wc_get_product_id_by_sku( $sku ) — a lookup table query. Not a meta_query on _sku.

How do you get a variable product's price range?

$product->get_variation_price( 'min' ) and ( 'max' ), or get_price_html(). Don't loop over all variations by hand.

How do you hide a meta field from the REST API?

A _ prefix doesn't protect it from REST: meta_data returns all meta. Filter it with woocommerce_rest_prepare_product_object, or don't keep sensitive data in product meta.

How does a global attribute differ from a local one?

A global attribute is a pa_* taxonomy shared by all products: you can filter the catalog by it. A local one lives only in one product and has no filters.

How does wc_get_products() differ from WC_Product_Query?

Not in principle: wc_get_products() is a wrapper that creates a WC_Product_Query and returns the result.

How does WooCommerce hide out-of-stock products?

With the outofstock term in the product_visibility taxonomy and the "Hide out of stock items" option. Catalog queries add a tax_query on that taxonomy.

How many variations per product is reasonable?

Hundreds are technically possible, but the product form and price calculation slow down. If there are thousands of combinations, rethink the model: separate products, add-ons or options instead of variations.

When do you need a custom product type?

When the product behaves differently: pricing, cart, shipping, post-payment handling. If only a few fields change, meta fields are enough.

Why not save_post for product fields?

save_post fires for any post and before WooCommerce saves its own data. woocommerce_admin_process_product_object gives you the product object and makes your changes part of the main save.

Cart and Checkout

Can you build a headless store on the Store API?

Yes, that's its main use case together with blocks. But payment on an external frontend depends on the payment gateway: not every gateway supports paying through the Store API.

Does the Store API need authentication?

No, it's the customer's public API. Changes need the Nonce header (CSRF protection) and a session or a Cart-Token.

How do you add a fee to an order?

woocommerce_cart_calculate_fees and $cart->add_fee( $name, $amount, $taxable ). Fees are calculated on the server, so they work in both checkouts.

How do you add a field to block checkout?

With the Additional Checkout Fields API: woocommerce_register_additional_checkout_field() on the woocommerce_init hook, with an id in the namespace/name format, a location and a field type.

How do you add your own data to a Store API response?

With woocommerce_store_api_register_endpoint_data() for the endpoint you need (cart, cart item). The data shows up in the extensions.<namespace> field.

How do you block checkout if the cart has incompatible products?

A check in woocommerce_check_cart_items with an error through wc_add_notice(): a cart with an error won't pass checkout, neither in the template nor through the Store API.

What is the checkout-draft status?

A draft order that block checkout creates while the customer fills in the form. It isn't visible as a regular order and is cleaned up on a schedule if the purchase isn't completed.

Which hooks work in both checkouts?

Everything that happens to the cart and the order on the server: fee and price calculation, coupons, woocommerce_new_order, status changes, woocommerce_payment_complete.

Why doesn't block checkout support the old form hooks?

The form is rendered by React on the client, and the data goes as a JSON request to the Store API. There is no PHP form template, so the hooks that inserted HTML into the form or read $_POST aren't there either.

Gutenberg for the Store

How do you pass data from PHP to the store?

wp_interactivity_state( 'namespace', [...] ) — global state; wp_interactivity_data_wp_context() — the local context of a specific block.

What is block context?

A way to pass data from a parent block to its children: providesContext on the parent, usesContext on the child. Product Template passes the postId of every product.

What is Product Collection?

A WooCommerce block for product lists with ready-made collections (new arrivals, on sale, best sellers, related products) and filters. The inner Product Template defines the product card from separate blocks.

What is the Interactivity API?

The WordPress standard for frontend interactivity: the server renders HTML with data-wp-* directives, and a small runtime binds them to a JS store. Blocks on the same page can share state.

When should a block be dynamic?

When the data changes independently of content editing: prices, stock, user data, post lists. Then render.php generates the HTML on every request.

Where are template changes made in the Site Editor stored?

In the database as a post of type wp_template. They take priority over the theme file until they are reset.

Why get_block_wrapper_attributes()?

It adds the classes and styles from supports (colors, spacing, alignment) to the block wrapper. Without it the inspector settings don't reach the markup.

Why is a block theme better for a store?

Store templates are edited without code, styles are centralized in theme.json, and block cart and checkout work by default. The price is a compatibility audit of plugins that depend on PHP templates.

Why is it better than jQuery or your own React?

No duplicated markup on the client, it works with server rendering, and the scripts are modules loaded only with the block. State can be passed from PHP through wp_interactivity_state().

Orders, Payments, Shipping

How do you add refunds to a gateway?

Add refunds to $this->supports and implement process_refund( $order_id, $amount, $reason ) calling the provider's API.

How do you add your own WooCommerce email?

A class extends WC_Email with trigger() and templates, registered through woocommerce_email_classes. Then the email has its settings in WooCommerce → Settings → Emails.

How does processing differ from completed?

processing — payment received, the order has to be packed and shipped. completed — fulfilled. For virtual and downloadable products WooCommerce sets completed right after payment.

What does payment_complete() do?

It sets the status (processing or completed), saves the transaction ID and the payment date, reduces stock if it wasn't reduced yet and fires the woocommerce_payment_complete hook.

What does process_payment() return?

An array with result (success or failure) and redirect — the URL to send the customer to: the provider's page or the thank-you page.

What is a shipping package?

An array with the cart items, the shipping address and the total, for which the methods calculate rates. The cart can be split into several packages with woocommerce_cart_shipping_packages.

Where do you plug in "after payment" logic?

woocommerce_payment_complete or woocommerce_order_status_processing, not the thank-you page. Heavy actions go through Action Scheduler.

Why is the shipping price "stuck"?

Rates are cached in the session by the package hash. If only the method settings changed, the cart takes the old cache. Clear the shipping cache in tests.

Why must a webhook be idempotent?

Providers retry delivery if they didn't get a 200 in time, and they may send several events about one payment. Processing it again must not change the result.

APIs and Integrations

How do you add a field to the order response?

The woocommerce_rest_prepare_shop_order_object filter or register_rest_field() for the matching type.

How do you authenticate with the WC REST API?

Consumer key / secret through Basic auth over HTTPS. For requests from your own site (admin, blocks) — a cookie + the wp_rest nonce.

How do you avoid a sync loop?

Mark changes coming from the external system (a meta or a runtime flag) and don't send them back. Or define a single source of truth for every field.

How do you check a WooCommerce webhook signature?

Calculate base64_encode( hash_hmac( 'sha256', $raw_body, $secret, true ) ) and compare it with X-WC-Webhook-Signature using hash_equals().

How do you get all orders if there are 10,000 of them?

Page through with per_page=100 following X-WP-TotalPages, or filter by date (modified_after) and sync incrementally.

How do you log an integration in WooCommerce?

wc_get_logger() with your own source. The logs are in WooCommerce → Status → Logs, with levels from debug to emergency.

How do you run the queue in production without depending on visits?

Disable WP-Cron (DISABLE_WP_CRON) and run wp cron event run --due-now and/or wp action-scheduler run from the system cron.

What is Action Scheduler?

A job queue library for WordPress, built into WooCommerce. Jobs are stored in the database, have groups, statuses and a log, and run in batches through WP-Cron, an async request or WP-CLI.

What is an upsert and why does it matter for a sync?

An "update if it exists, otherwise create" operation by a stable key. Running it again doesn't create duplicates — the sync can be safely restarted.

Performance and Security

Does a nonce protect against unauthorized access?

No. A nonce protects against CSRF — a forged request on behalf of the user. Whether the user has the right to the action is checked by current_user_can() or an owner check of the resource.

What are cart fragments and why are they criticized?

A mechanism that updates the mini cart with the get_refreshed_fragments AJAX request. It made an uncached server request on every page. In modern versions the script loads only where the classic cart widget is.

What does an object cache give you?

It keeps query results and transients in memory (Redis, Memcached) between requests. Fewer SQL queries on every page, especially for logged-in users and the cart.

What is IDOR in a store?

Insecure Direct Object Reference: a customer changes the order_id in a request and gets someone else's order. The protection is a check that the order belongs to the current user, or access by the order key.

When do you sanitize and when do you escape?

Sanitize on input, before saving. Escape on output, in the output context (HTML, attribute, URL). One doesn't replace the other.

Which metrics are part of Core Web Vitals?

LCP (how fast the main content appears), INP (how fast the page reacts to actions) and CLS (layout stability).

Which WooCommerce tables grow fast?

Sessions (woocommerce_sessions), Action Scheduler jobs and logs, order meta, draft orders. They need cleanup and size monitoring.

Why can lab data differ from field data?

The lab is one run on an emulated device. Field data (CrUX) comes from real users with different devices, networks and caches.

Why can't the cart and checkout be fully cached?

They are personal: the cart, the address, the discounted prices of a specific customer. A page cache would serve one customer another customer's cart. So they are excluded from the cache, and WooCommerce sets cookies that caching plugins and hosts use to bypass the cache for customers.

Quality and Production

How do you review a junior's code?

The big picture first, then the details. Separate the must-haves from the nice-to-haves. Explain the reason and give links. Praise good decisions. Big changes — talk them through, not 40 comments.

How do you test logic that lives in hooks?

Move the logic into separate classes with pure methods, and only call them from the hook. Then unit tests cover the logic and integration tests cover the hook registration.

How does PHPCS differ from PHPStan?

PHPCS checks style and patterns (WPCS: escaping, nonce, prepare). PHPStan is static analysis of types and logic: non-existent methods, wrong types, dead code.

What do you automate in a PR?

Style (PHPCS), static analysis (PHPStan), tests, the JS build. The human keeps architecture, business logic and security in context.

What is special about Pantheon for a WordPress developer?

Clear Dev → Test → Live environments, code only through git, a read-only file system on Live and Test (except uploads), built-in Redis and edge-level caching.

What is wp-env?

The @wordpress/env tool that runs WordPress in Docker with the plugins you need, from a .wp-env.json config. Handy for local development and for tests in CI.

What should be excluded from the host cache for WooCommerce?

The cart, checkout, My Account and requests with the woocommerce_items_in_cart, woocommerce_cart_hash, wp_woocommerce_session_* cookies. Managed hosts usually do it themselves, but it has to be checked.

What should E2E tests cover in a store?

The critical money path: add to cart, apply a coupon, place an order with a test payment method, get the thank-you page. For both classic and block checkout if both are used.

Why can't you move the database from staging to a store's production?

Production keeps getting new orders, customers and stock changes. Moving the staging database would overwrite that data. Settings changes are moved by hand, with migration scripts or by exporting specific settings.

Interview

How do you answer a WooCommerce system design question?

Clarify the requirements and the numbers, then data, flows, risks, verification. Name the choice "ready plugin / own code / external service" explicitly and say why.

What do you ask before designing?

Volumes (products, orders, peaks), the source of truth for the data, integrations, payment and tax requirements, who will maintain the solution, budget and deadlines.

What do you do if you don't know the answer?

Say so honestly and show your reasoning: what related things you know, where you would look, how you would check. The interviewer evaluates thinking, not memory.

What do you do in live coding if you get stuck?

Say what exactly doesn't work and what your hypotheses are. Asking for a hint is better than 5 minutes of silence. The interviewer evaluates the process.

What do you say about the block cart in the progress bar task?

That the woocommerce_before_cart hook works only in the classic cart. For the block cart — extend the Store API with your data and show it through a block or a cart slot.

What separates a middle answer from a junior one?

A junior describes what to do. A middle developer explains why, what the alternatives are, what can go wrong and how they will check it.

When do you write your own code and when do you take a ready plugin?

A ready plugin when the feature is standard and critical for money (subscriptions, payments, taxes) and the plugin is maintained. Your own code when the business is specific and ready solutions need more workarounds than your own code would.

Which questions should you ask the company?

How code review and deploys work, which WooCommerce versions and themes the projects use, who talks to the clients, how tasks are estimated, whether there are tests and staging.

Why isn't woocommerce_product_get_price enough for variations?

Variations need a separate woocommerce_product_variation_get_price filter, and the price range of a variable product is cached. Without changing the cache hash the catalog will show the old range.