Skip to main content

3 posts tagged with "WP-CLI"

View all tags

wp eval Works but REST 500s? Three WordPress Context Traps

Β· 9 min read

Three quiet WordPress plugin behaviors surfaced while building CCLEE B2B β€” a WooCommerce B2B plugin covering user management, differential pricing, quoting, and bulk ordering. The entry point was its PDF catalog download: on production the button returned the generic fatal-error page while the very same logic ran via wp eval; fixing the first layer exposed the second, and the second the third. The three root causes live on three different layers β€” deploy, context, filesystem β€” and they fit in one post.

TL;DR​

  1. Deploy layer: CI/rsync deploys never run composer install. If the plugin's vendor/ is hidden by stacked .gitignore rules (plugin-level /vendor/ plus repo-level vendor/ and plugins/), it never enters git, and the first new after require autoload is a Fatal. Fix: remove the ignore chain, commit vendor, smoke-test with class_exists after deploy.
  2. Context layer: REST requests never load wp-admin/includes/, so admin-only functions like wp_tempnam() throw Call to undefined function. wp eval works because CLI loads full WordPress β€” "it works in CLI" proves nothing about the REST context. Fix: function_exists guard plus a tempnam(sys_get_temp_dir(), ...) fallback.
  3. Filesystem layer: mPDF's default temp directory sits at vendor/mpdf/mpdf/tmp/. In the container, rsync preserved owner UID 1001 while PHP-FPM runs as www-data (UID 82), is_writable returns false, and chown fails on the volume-mounted filesystem. Fix: pass an explicit tempDir under the system temp directory at construction.

WooCommerce Variable Product Price Not Changing? Parent Only

Β· 5 min read

Running regular_price updates against a Variable product via WP-CLI completes with a success message and the admin shows the new price β€” yet the product page and the JSON-LD keep displaying the old one.

Ran into this while building Cross-border Product Listing Assistant β€” one-click product sourcing with AI-generated descriptions and pricing, published to WooCommerce after review β€” and stepped on a quiet WooCommerce behavior.

TL;DR​

wp wc product update on a Variable product writes the parent product's meta only β€” no iteration, no cascade, no hint. The storefront price and the JSON-LD schema both read the variation's _price, while the parent price serves only the admin display, and the wc_product_meta_lookup table keeps the old value too. The fix: list every variation under the parent, then update them one by one with wp wc product_variation update.

Symptom: Command Succeeds, Storefront Price Doesn't Move​

wp wc product update 187 --regular_price="16.00" --user=admin --allow-root
# Success: Updated product 187.

Three observations make up the full picture:

  1. The command returns success, without any warning;
  2. In the admin, the parent product's price field already shows the new value;
  3. The product page, price filters, and JSON-LD structured data all still show the old price.

Searches like "price not updating" or "changed price but storefront unchanged" all describe this path. The confusing part is the success message β€” it truthfully reports "parent updated", it just never claims the parent is where the storefront price comes from.

Root Cause: The Parent Price Is Admin Display, the Real Price Lives in Variations​

A Variable product's price storage is layered: the parent's regular_price in meta serves the admin edit screen; the product page display, cart calculations, and the JSON-LD schema all read each variation's own _price.

wp wc product update stops exactly at the parent layer β€” it does not iterate variations, does not cascade, and does not warn. After it writes the parent meta:

  • Every variation's _price is untouched;
  • WooCommerce's performance lookup table wc_product_meta_lookup (created in its class-wc-install.php) also keeps the old value, so read paths going through the lookup table return the old price as well.

Of a three-layer read system, only the least important layer got updated. Nothing along the chain ever says "variations not synced" β€” which is what makes this expensive to diagnose: every step looks like success.

A cache layer holding stale values and bypassing the normal update chain is not unique to WooCommerce β€” Yoast SEO's og:image serves an indexable cache string directly, bypassing the attachment API; same-shaped root cause, see Yoast og:image Not Following CDN.

Fix: Update the Variations One by One​

First list every variation under the parent:

wp wc product list --parent=187 --fields=id,sku,regular_price --user=admin --allow-root

Then update them individually (wp wc product_variation update accepts one VID per call):

wp wc product_variation update 187 1201 --regular_price="16.00" --user=admin --allow-root
wp wc product_variation update 187 1202 --regular_price="16.00" --user=admin --allow-root

Updating through the variation endpoint goes through WooCommerce's CRUD: the variation meta and the wc_product_meta_lookup table get synced by WooCommerce itself, so the storefront, JSON-LD, and filters all read one consistent new price. For products with many variations, a loop script handles it β€” one VID per call.

All commands here run inside a Docker container; see Running WP-CLI in Docker for the containerized setup.

Caution

The wp wc command family requires an authenticated user β€” never drop --user; and do not take the shortcut of a raw database UPDATE β€” bypassing CRUD desyncs the wc_product_meta_lookup table from the meta, and the storefront can still read the old price.

FAQ​

Why does the admin show the new price while the storefront keeps the old one?​

Two separate read paths: the parent product's edit screen reads the parent's own meta, while the storefront price and JSON-LD both come from the variation's _price. Updating the parent only refreshes the admin-facing copy; the storefront path never moves.

Can I just UPDATE the _price rows in the database?​

Not recommended. Writing to wp_postmeta directly leaves the wc_product_meta_lookup table out of sync, and some read paths keep returning the old price. Use wp wc product_variation update so WooCommerce's CRUD syncs both stores.

Is there a way to update all variations in bulk?​

wp wc product_variation update accepts one VID per call, so bulk updates need a script loop: list every variation ID with --parent first, then run the update for each.

Do Simple products have this problem too?​

No. Simple products have no variations, so the price wp wc product update writes is the storefront price. The non-cascading update is a structural issue unique to Variable products.

CCLEE

Independent developer, 24 years in e-commerce, focused on grounding AI in real business scenarios.

Work with me