Skip to content

Overriding WooCommerce templates in your theme safely

How wc_get_template resolves a path, how to copy a single WooCommerce template into your child theme without breaking upgrades, and how to clear the outdated-templates warning in WooCommerce Status.

WooCommerce renders almost every storefront fragment through wc_get_template(), and that function checks your theme before it checks the plugin. Create a woocommerce/ folder inside your child theme, mirror the plugin’s path with the templates/ prefix removed, and your copy is the one that runs. The cost is ownership: your copy is frozen at the WooCommerce version you copied it from, and every later release that edits the original quietly leaves your file behind. So copy one file, never the whole folder — and reach for an action or filter hook first, because a hook costs nothing at upgrade time.

What you’ll accomplish

  • Trace the exact order wc_get_template() searches, so you know which file actually renders.
  • Copy a single WooCommerce template into your child theme without dragging the rest of the directory along.
  • Read the @version docblock and tell when WooCommerce has moved past your copy.
  • Clear the outdated-override warning in WooCommerce > Status.
  • Decide, before copying anything, whether a hook does the job for free.

Prerequisites

  • WooCommerce 8.0 or newer on a current WordPress release, and shell access with WP-CLI (or SFTP if that is all you have).
  • A child theme you control. If you do not have one yet, start with creating a WordPress child theme — overrides placed in a parent theme you did not write get wiped on the next theme update.
  • Your theme declares WooCommerce support with add_theme_support( 'woocommerce' ) in its functions.php. Without it, WooCommerce wraps shop pages in its own generic markup and your override sits inside a container you did not expect.
  • A staging copy of the store. Template edits touch the pages that take money.

The block versus shortcode split, said plainly. If your Cart and Checkout pages use the Cart and Checkout blocks — the default for any store set up since 2023 — then copying templates/cart/cart.php, templates/checkout/form-checkout.php, templates/checkout/review-order.php or templates/checkout/form-billing.php into your theme does nothing at all. Those blocks render client side from the Store API; the classic PHP templates are never loaded, so there is no file to override and no error to tell you so. Block Cart and Checkout are customized through block settings in the editor, through the additional-fields API (woocommerce_register_additional_checkout_field()), and through Store API filters. Everything in this guide applies to the classic shortcode Cart and Checkout, to product and archive templates, to My Account, and to emails — all of which still run through wc_get_template().

To check which one you have, open the Checkout page in the editor: a single [woocommerce_checkout] shortcode block means classic, a Checkout block with inner blocks means the block flow.

How it works

wc_get_template( $template_name, $args, $template_path, $default_path ) does two things: it resolves a filesystem path, then it includes it. The resolution happens in wc_locate_template(), which asks WordPress core’s locate_template() for the file inside your theme first, and only falls back to WC()->plugin_path() . '/templates/' when the theme has nothing.

Because locate_template() checks the stylesheet directory before the template directory, the practical cascade for one file looks like this.

The lookup cascade wc_get_template walks for one template file, from the child theme woocommerce folder down to the WooCommerce plugin templates directory, with the first match being included

Three details matter. First, the theme folder name comes from WC()->template_path(), which is woocommerce/ unless a plugin filters woocommerce_template_path — most stores never touch it. Second, the bare theme-root paths at steps 3 and 4 are a legacy fallback; do not use them, because a file named single-product/title.php at your theme root is indistinguishable from an ordinary theme template. Third, the resolved path is stored in the object cache keyed by template name and WooCommerce version, so a brand-new override may not appear until the cache is flushed.

Each shipped template carries a docblock like @version 3.4.0. That number is the WooCommerce release in which the file last changed — not the WooCommerce version you are running. It is the only handle you have on drift, and the Status page uses it.

Step-by-step

  1. Confirm the child theme is the active stylesheet. An override in a child theme that is not active is dead weight.

    wp theme list --status=active --field=name

    Expect the child theme’s directory name, for example shop-child. If you see the parent name, activate the child first.

  2. Find the exact template WooCommerce loads for the page you want to change. Guessing from the file tree is slow. Drop this in the child theme’s functions.php on staging, load the page once, then remove it.

    add_action( 'woocommerce_before_template_part', function ( $template_name ) {
        error_log( 'wc template: ' . $template_name );
    }, 10, 1 );

    Your PHP error log then names every fragment in render order:

    wc template: single-product/title.php
    wc template: single-product/price.php
    wc template: single-product/add-to-cart/simple.php
  3. Resolve the two directories you will be copying between. Capture them as shell variables so no path is typed twice.

    WC=$(wp plugin path woocommerce --dir)
    CHILD=$(wp eval 'echo get_stylesheet_directory();')
    printf '%s\n%s\n' "$WC" "$CHILD"

    Expected output is two absolute paths:

    /var/www/example.com/wp-content/plugins/woocommerce
    /var/www/example.com/wp-content/themes/shop-child
  4. Copy exactly one file, preserving its subdirectories minus templates/. Copying the whole templates/ tree is the single most common way stores end up with 180 stale overrides.

    mkdir -p "$CHILD/woocommerce/single-product"
    cp "$WC/templates/single-product/title.php" "$CHILD/woocommerce/single-product/title.php"
    ls -l "$CHILD/woocommerce/single-product/title.php"

    Success looks like a file listed at the new path with a non-zero size.

  5. Record the version you forked from. Read it out of the file you just copied and put it somewhere you will look again — a CHANGELOG.md in the theme, or the commit message.

    grep -m1 '@version' "$CHILD/woocommerce/single-product/title.php"
     * @version 3.4.0

    Do not edit that number. It is what the Status page compares against.

  6. Make the smallest edit that gets the result. Keep the docblock, keep the defined( 'ABSPATH' ) || exit; guard, keep the existing do_action() calls — other plugins hook into them, and deleting one silently removes their output. If your change is purely additive markup, add it around the original code rather than rewriting the file.

  7. Flush the cache and load the page. The located path is cached, and a page cache sits in front of it on most stores.

    wp cache flush
    Success: The cache was flushed.

    Now hard-reload the product page in a private window. Your markup should be there.

Validate it works

Open WooCommerce > Status and scroll to the Templates section. Every override you created is listed under Overrides, and each one whose @version matches the shipped file is shown plainly with a check. A file that has fallen behind gets a red note reading roughly version 3.4.0 is out of date. The core version is 9.4.0, and an extra Outdated templates warning row appears above the list. A store in good shape shows the overrides list with no red entries and no outdated-templates row at all.

Check the same thing from the shell so it can run in CI or a cron:

cd "$CHILD/woocommerce" || exit 1
find . -name '*.php' | sed 's|^\./||' | while read -r f; do
  mine=$(grep -m1 -oE '@version[[:space:]]+[0-9.]+' "$f" | awk '{print $2}')
  core=$(grep -m1 -oE '@version[[:space:]]+[0-9.]+' "$WC/templates/$f" | awk '{print $2}')
  [ "$mine" = "$core" ] || printf 'DRIFT %-44s yours=%s core=%s\n' "$f" "$mine" "$core"
done

A clean store prints nothing. After a WooCommerce upgrade that touched one of your files you get a line per drifted override:

DRIFT single-product/title.php                     yours=3.4.0 core=9.4.0

When that fires, diff your copy against the current shipped file and hand-merge the upstream change:

diff -u "$WC/templates/single-product/title.php" "$CHILD/woocommerce/single-product/title.php"

Everything that is not your own edit is a change WooCommerce made that your store is currently missing.

Troubleshooting

The override is ignored entirely. Nine times out of ten the path is wrong. The theme folder must be named woocommerce, and the path underneath it drops the plugin’s templates/ segment — woocommerce/cart/cart.php, not woocommerce/templates/cart/cart.php. Compare the two trees directly:

diff <(cd "$CHILD/woocommerce" && find . -name '*.php' | sort) \
     <(cd "$WC/templates" && find . -name '*.php' | sort) | grep '^<'

Any line printed here is a file in your theme that does not exist in the plugin — a typo’d path, a renamed template, or a leftover from an old WooCommerce version. None of them are being loaded.

New markup vanished after a WooCommerce upgrade. This is the same failure the version check catches, seen from the other side. WooCommerce added a field, a hook, or a wrapper to the original template; your frozen copy still renders the older markup, so the new feature never appears and nothing errors. The give-away is a feature working on a default theme but not on yours. Run the drift script, diff, merge, then update your own record of the version.

The change does nothing on the Checkout page. Re-read the Prerequisites. If the page uses the Checkout block, checkout/form-checkout.php is not loaded and never will be. The same applies to cart/cart.php under the Cart block and to checkout/thankyou.php where the Order Confirmation block has taken over. Emails, My Account, product and archive templates are unaffected and still override normally.

A parent-theme override shadows yours, or vice versa. Commercial WooCommerce themes frequently ship their own woocommerce/ directory. Your child-theme file wins for the same relative path, but only for that exact path — if the parent overrides content-product.php and you override loop/price.php, you are editing a file the parent’s copy may not even call. List what the parent already claims before you start:

find "$(wp eval 'echo get_template_directory();')/woocommerce" -name '*.php' | wc -l

If that number is large, prefer hooks; you are working inside someone else’s fork.

The edit is on disk but not on screen. Object cache, page cache, and OPcache each hide a fresh template independently. Run wp cache flush, purge the page cache at the CDN or plugin level, and reload PHP-FPM if OPcache validation is off. If it is still stale, set define( 'WC_TEMPLATE_DEBUG_MODE', true ); in wp-config.php on staging: that constant forces WooCommerce to load its own templates and ignore every override, which tells you in one page load whether your file is involved at all. Remove it afterwards — it is a diagnostic, not a setting.

When this is the wrong approach

An override is a permanent maintenance obligation attached to a file someone else keeps editing. Most of what people copy templates for is reachable from a hook that has no such obligation.

Decision tree: block Cart or Checkout means it is not a template job, a hook that can produce the change should be used instead of an override, and only markup no hook can reach justifies copying a file

Move or remove a section of the product page with remove_action() and add_action() on woocommerce_single_product_summary. Change price output with the woocommerce_get_price_html filter. Change the button label with woocommerce_product_add_to_cart_text. Add or reorder classic checkout fields with woocommerce_checkout_fields. Insert markup around a listing item with woocommerce_before_shop_loop_item or woocommerce_after_shop_loop_item. None of these leave a file to re-merge, and none of them appear on the Status page as drift. The official template structure documentation lists which hooks each shipped template fires, and the wider WooCommerce developer documentation covers the block-side APIs.

Overriding is also the wrong tool when the real problem is not markup. Restyling is CSS. Reordering is usually a setting or a hook priority. And if checkout is slow rather than wrong, no template edit will help — that is a capacity and query problem, covered in WooCommerce checkout timing out under load.

The honest rule after years of running these stores: an override you cannot justify in one sentence is an override you will forget, and forgotten overrides are how a store ends up rendering a checkout from three major versions ago.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.