Skip to content

WooCommerce: Sorry, this product cannot be purchased

Fix the WooCommerce error “Sorry, this product cannot be purchased.” by finding which check failed for your product. You will test the product from the command line, then correct its price, its status, a variation or a plugin filter.

Your WooCommerce store answers “Sorry, this product cannot be purchased.” when a shopper tries to add a product to the cart. Sometimes the product page has no Add to cart button at all. This page is for the store owner or developer who needs that product selling again. WooCommerce shows the message when one function, is_purchasable(), answers no for the product. That function runs four checks, and a blank price field is the first one to look at. One command shows you which check failed, and each check has a short fix.

What you’ll accomplish

  • Tell this message apart from the out-of-stock and sold-individually messages, which come from other checks.
  • See, for one product ID, which of the four checks behind is_purchasable() fails.
  • Fix the cause, whether it is a blank price, an unpublished product, a disabled variation or a plugin filter.
  • Repair products whose stored price was left empty by a script or a direct database change.
  • Confirm the fix as a logged-out shopper.

Prerequisites

  • WooCommerce 11.0 or newer. The conditions and messages quoted here were checked against the WooCommerce 11.3.0 source, the current stable release. Version 11.0 applies the same four conditions. From 11.1 the status test sits in a helper named is_viewable(), and the behaviour is unchanged.
  • An administrator account, and shell access with WP-CLI (the wp command). Run the commands from the site root as the user who owns the files.
  • The product ID. In Products, hover over the product name and read the number after “ID:”. The examples use the simple product 2417, the variable product 2630 and its variation 2644.
  • The SQL examples assume the default wp_ table prefix. Run wp db prefix to see yours.

How it works

The three checks WooCommerce runs when a product is added to the cart, from top to bottom. Check one, sold individually and already in the cart, answers "You cannot add another … to your cart." Check two, can it be purchased, is highlighted and groups four conditions: the product exists, it is published or you can edit it, the price is not blank, and no plugin filter says no. Any of the four answers "Sorry, this product cannot be purchased." Check three, in stock, answers "You cannot add … to the cart because the product is out of stock." A product that passes all three is added to the cart.

When a shopper adds a product to the cart, WooCommerce runs three checks in a fixed order. It stops at the first one that fails, and each check has its own message. The wording you see tells you which check to look at.

MessageCheck that failedMeaning
You cannot add another “Cedar Bench” to your cart.is_sold_individually()Sold individually is ticked and the product is already in the cart.
Sorry, this product cannot be purchased.is_purchasable()One of the four conditions below is false.
You cannot add “Cedar Bench” to the cart because the product is out of stock.is_in_stock()The stock status is “Out of stock”.

Only the middle row is the subject of this page. Stock is not its cause.

is_purchasable() answers yes only when all four of these are true:

  1. The product exists. The ID points to a real product.
  2. The current visitor may view it. The product status is publish, or the visitor is logged in with the right to edit that product. For a variation, the parent product must pass the same test.
  3. The price is not blank. A price of 0 counts as a price. An empty field does not.
  4. No filter changes the answer. WooCommerce passes the result through a filter named woocommerce_is_purchasable. A filter is a hook that lets a plugin or theme replace a value, so any of them can turn a yes into a no.

A variation, which is one purchasable combination of a variable product such as “Large, Blue”, has one extra rule. It must be enabled and have its own price. WooCommerce calls this variation_is_visible(). The variation result then passes through a second filter, woocommerce_variation_is_purchasable.

Two product types start from no, external (affiliate) products and grouped products. Only a filter can turn that into a yes. The last section explains why.

The same function controls the button. On a product page, a simple product gets no Add to cart form when the answer is no. On shop and category pages, the button reads “Read more” in place of “Add to cart”. Shoppers then meet the message through another route, such as a direct ?add-to-cart= link, a cached page or a custom button.

Step-by-step

1. Confirm which message you have. Open a private browser window, so you are logged out, and load this address with your own domain and product ID:

https://example.com/?add-to-cart=2417

An error notice appears at the top of the page, or on the next shop page you open. If it reads “Sorry, this product cannot be purchased.”, continue with step 2. If it mentions stock, see stock management and backorders. If nothing appears and the cart stays empty, the ID does not exist or the product is in the trash. WooCommerce refuses both without any message. For a variable product, this link only answers “Please choose product options by visiting…”, so go straight to step 2.

2. Ask WooCommerce what it sees. This command prints each value that is_purchasable() reads. WP-CLI runs with no logged-in user, so the answer is the one a guest shopper gets.

wp eval '
$p = wc_get_product( 2417 );
if ( ! $p ) { echo "No product with that ID\n"; return; }
$parent = $p->get_parent_id();
printf( "type:            %s\n", $p->get_type() );
printf( "status:          %s\n", $p->get_status() );
printf( "parent status:   %s\n", $parent ? get_post_status( $parent ) : "-" );
printf( "price (stored):  [%s]\n", $p->get_price( "edit" ) );
printf( "price (shown):   [%s]\n", $p->get_price() );
printf( "regular price:   [%s]\n", $p->get_regular_price( "edit" ) );
printf( "in stock:        %s\n", $p->is_in_stock() ? "yes" : "no" );
printf( "purchasable:     %s\n", $p->is_purchasable() ? "yes" : "no" );
'

Example output:

type:            simple
status:          publish
parent status:   -
price (stored):  []
price (shown):   []
regular price:   []
in stock:        yes
purchasable:     no

Read the output from top to bottom and stop at the first line that matches this table.

What the output showsFailing checkGo to
No product with that IDThe product does not existCheck the ID in Products
type is external or groupedBy design“When this is the wrong approach”
status or parent status is not publishStatusStep 4
type is variableOne or more variationsStep 5
price (stored) is [] and regular price is []Blank priceStep 3
price (stored) is [] and regular price has a valueStored price out of syncStep 7
price (stored) has a value and price (shown) is []A plugin empties the priceStep 6
Every value is fine and purchasable is still noA filterStep 6

A variable product has no price field of its own, so its regular price line is normally []. Run the command on the parent ID to check its status, then go to step 5.

3. Fix a blank price. Edit the product, open Product data, then General, and fill in Regular price. For a free product, type 0. A blank field means “no price set”, and WooCommerce will not sell a product with no price. The same change from the shell:

wp wc product update 2417 --user=1 --regular_price=0
wp post meta get 2417 _price

Example output:

Success: Updated product 2417.
0

Replace 1 with the ID of an administrator account. Every wp wc command needs --user, because the WooCommerce REST API behind it checks permissions. If the second line prints nothing, the price was not saved.

4. Fix the product status. List every product that is not published:

wp post list --post_type=product --post_status=draft,pending,private --fields=ID,post_title,post_status

Example output:

+------+-------------------+-------------+
| ID   | post_title        | post_status |
+------+-------------------+-------------+
| 2417 | Cedar Planter Box | draft       |
| 2588 | Trade Sample Pack | private     |
+------+-------------------+-------------+

A draft, pending or private product can be bought only by someone allowed to edit it, which in practice means administrators and shop managers. Everyone else gets the message. If the product should be on sale, publish it:

wp post update 2417 --post_status=publish

The expected reply is Success: Updated post 2417. If you keep a product private on purpose, the message is the correct behaviour for visitors who cannot edit it.

5. Check each variation. On a variable product, every variation is checked on its own. List them all:

wp eval '
foreach ( wc_get_product( 2630 )->get_children() as $id ) {
	$v = wc_get_product( $id );
	printf( "%d  status=%s  price=[%s]  visible=%s  purchasable=%s\n", $id, $v->get_status(), $v->get_price( "edit" ), $v->variation_is_visible() ? "yes" : "no", $v->is_purchasable() ? "yes" : "no" );
}
'

Example output:

2643  status=publish  price=[34.00]  visible=yes  purchasable=yes
2644  status=publish  price=[]  visible=no  purchasable=no
2645  status=private  price=[34.00]  visible=no  purchasable=no

Variation 2644 has no price. Variation 2645 is disabled, since WooCommerce stores a disabled variation with the status private. Unlike a product, a disabled variation is refused for everyone, administrators included. To fix both in the admin, open the Variations tab, tick Enabled and fill in the regular price. From the shell:

wp wc product_variation update 2630 2644 --user=1 --regular_price=34.00 --status=publish

The expected reply is Success: Updated product_variation 2644. Run the list again. Every variation you sell must show purchasable=yes.

On the product page, WooCommerce leaves these variations out of the form. The matching options disappear from the dropdowns, or a shopper who picks that combination reads “Sorry, no products matched your selection. Please choose a different combination.” If every variation is hidden, the page says “This product is currently out of stock and unavailable.”, even though stock is not the problem.

6. Find the filter that says no. When the product data is fine, a plugin or the theme is changing the answer. This command lists every piece of code attached to the five filters that can do it:

wp eval '
global $wp_filter;
$hooks = array( "woocommerce_is_purchasable", "woocommerce_variation_is_purchasable", "woocommerce_variation_is_visible", "woocommerce_product_get_price", "woocommerce_product_variation_get_price" );
foreach ( $hooks as $hook ) {
	if ( empty( $wp_filter[ $hook ] ) ) { continue; }
	foreach ( $wp_filter[ $hook ]->callbacks as $priority => $callbacks ) {
		foreach ( $callbacks as $cb ) {
			$fn = $cb["function"];
			if ( is_string( $fn ) && strpos( $fn, "::" ) ) { $fn = explode( "::", $fn ); }
			if ( is_object( $fn ) && ! ( $fn instanceof Closure ) ) { $fn = array( $fn, "__invoke" ); }
			$ref = is_array( $fn ) ? new ReflectionMethod( $fn[0], $fn[1] ) : new ReflectionFunction( $fn );
			printf( "%s  priority %d  %s:%d\n", $hook, $priority, str_replace( ABSPATH, "", $ref->getFileName() ), $ref->getStartLine() );
		}
	}
}
'

Example output:

woocommerce_is_purchasable  priority 10  wp-content/plugins/example-catalog-mode/includes/class-rules.php:88
woocommerce_product_get_price  priority 20  wp-content/themes/example-child/functions.php:142

Each line names a file and a line number, and the folder tells you which plugin or theme owns the code. Some plugins attach their filters only on front-end pages, so an empty list is not full proof.

The WooCommerce source code notes that extensions use woocommerce_is_purchasable to allow or refuse buying by user role, membership, location or login status. That points to membership, catalog-mode, wholesale and country-restriction plugins. To prove which one is responsible, repeat a short test with that plugin skipped for one command:

wp --skip-plugins=example-catalog-mode eval 'echo wc_get_product( 2417 )->is_purchasable() ? "yes" : "no";'

If the answer changes to yes, that plugin is the cause. Use --skip-themes in the same way to test the theme. Then change the rule in that plugin’s settings that covers this product or customer group. Many rules depend on who is logged in, so also test as a real customer, using that customer’s ID:

wp eval --user=58 'echo wc_get_product( 2417 )->is_purchasable() ? "yes" : "no";'

7. Repair a stored price that is out of sync. WooCommerce stores three price fields for each product, as post meta in the wp_postmeta table. _regular_price and _sale_price are what you type. _price is the price in effect right now, and it is the only one is_purchasable() reads. WooCommerce fills _price itself when a price or a sale date changes through the editor, the REST API or the built-in CSV importer. A script or import tool that writes _regular_price straight into the database skips that step and leaves _price empty. Saving the product again without changing a price does not refill it. Find the affected products:

wp db query "SELECT p.ID, p.post_type, r.meta_value AS regular_price, pr.meta_value AS price
FROM wp_posts p
JOIN wp_postmeta r ON r.post_id = p.ID AND r.meta_key = '_regular_price' AND r.meta_value <> ''
LEFT JOIN wp_postmeta pr ON pr.post_id = p.ID AND pr.meta_key = '_price'
WHERE p.post_type IN ('product','product_variation')
AND p.post_status = 'publish'
AND (pr.meta_value IS NULL OR pr.meta_value = '');"

Example output:

+------+-------------------+---------------+-------+
| ID   | post_type         | regular_price | price |
+------+-------------------+---------------+-------+
| 2644 | product_variation | 34.00         | NULL  |
| 2702 | product           | 18.50         |       |
+------+-------------------+---------------+-------+

No rows means no product has this problem. Otherwise, put the IDs from your output in the array( … ) below. The loop writes to the database, so the first command saves a backup in your home directory, outside the web root. The next commands clear the object cache, set _price the way WooCommerce would, and refresh the parent of each variation.

wp db export ~/before-price-repair.sql
wp cache flush
wp eval '
foreach ( array( 2644, 2702 ) as $id ) {
	$p = wc_get_product( $id );
	if ( ! $p ) { continue; }
	$p->set_price( $p->is_on_sale( "edit" ) ? $p->get_sale_price( "edit" ) : $p->get_regular_price( "edit" ) );
	$p->save();
	if ( $p->get_parent_id() ) { WC_Product_Variable::sync( $p->get_parent_id() ); }
}
'
wp wc tool run regenerate_product_lookup_tables --user=1

The export replies Success: Exported to followed by the file path. Stop there if it reports an error. The last command rebuilds wc_product_meta_lookup, the table WooCommerce uses to sort and filter the shop by price. It does not decide whether a product can be bought, but it holds the same stale prices. The command replies Success: Updated system_status_tool regenerate_product_lookup_tables. and the rebuild runs in the background. Run the SQL query again. It must return no rows.

Validate it works

Run the command from step 2 again, without --user. The last line must read purchasable: yes.

Then check what a guest receives from the web server. Use the address of the product page:

curl -s https://example.com/product/cedar-planter-box/ | grep -c 'single_add_to_cart_button'

single_add_to_cart_button is the CSS class that the standard WooCommerce templates and blocks put on the product page button. For a simple product, a result of 1 or more means the button is in the page. A result of 0 means the page has no such button, so go to the first Troubleshooting entry. A theme or page builder with its own product template may use another class. In that case, search the page source for your theme’s button instead.

This check does not prove a variable product. Its form and button stay in the page as long as one variation can be shown, so rely on the list from step 5.

Last, open https://example.com/?add-to-cart=2417 in a private window. The notice now says the product “has been added to your cart”.

Troubleshooting

The command says yes, and shoppers still see no button. A page cache is serving the old page. Purge the product address in your cache plugin or content delivery network (CDN), then run the curl check again. If the site uses a persistent object cache such as Redis, run wp cache flush as well.

It works for you and fails for customers. You are logged in as someone who can edit the product, so condition 2 lets you through. wp wc product get 2417 --user=1 --field=purchasable has the same bias, because it answers as that administrator. Use the step 2 command, which answers as a guest, then check the status in step 4.

The shop page shows “Read more” on a variable product whose variations are fine. The parent product keeps its own _price, copied from its variations, and it is empty. Refresh it with wp eval 'WC_Product_Variable::sync( 2630 );' and reload the shop page.

The cart page says a product “cannot be purchased. Please remove it from your cart.” The block-based cart and checkout run the same check on products already in the cart. This one stopped being purchasable after the shopper added it. Work through steps 2 to 7 for that product.

The message reads “Cedar Bench” is not available for purchase. This wording comes from the Store API, the REST interface behind the WooCommerce blocks. Block-based product pages and headless storefronts add to the cart through it. It runs the same is_purchasable() check. The steps above apply unchanged.

The message has other wording. A plugin can reword the classic message through the filter woocommerce_cart_product_cannot_be_purchased_message. The check behind it is the same.

When this is the wrong approach

If the button is on the page and a click does nothing, with no message, the problem is in the browser script, the request or the session. Follow the add to cart triage runbook for that case.

If the product is external or grouped, the answer is no by design. An external product shows a button that leads to another site. A grouped product lists its child products, and each child must be purchasable. Change the product type to simple if you want to sell it directly.

Product types added by extensions, such as subscriptions, can replace is_purchasable() with their own rules. When the product data and the filters above are all fine, read that extension’s documentation.

For reference, the WooCommerce product documentation covers the product editor, including the price fields and variations used above. The function itself is in the WooCommerce source code, in plugins/woocommerce/includes/abstracts/abstract-wc-product.php.

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