WooCommerce产品在没有实际缺货的情况下显示“缺货”消息

时间:2014-07-08 18:35:52

标签: php mysql wordpress woocommerce

产品随机显示的客户网站存在问题

  

“该产品目前无货存在且无法使用。”

问题是我们没有启用库存跟踪,所有产品都应该一直有库存。

当我进入WordPress管理员并单击产品的更新按钮(不更改任何内容)时,消息消失,“添加到购物车”按钮显示应该。不幸的是,这个问题在未来会重复出现并修复它我必须再次更新产品(同样点击WooCommerce设置中的更新会暂时解决问题)。

我需要找到一种方法来永久解决这个问题,这样它就不会自行恢复。

网站详细信息:

  • 使用WordPress 3.9.1
  • WooCommerce 2.1.12
  • PHP 5.3.10(也在本地尝试使用5.5.10)

我尝试了什么

  • 删除所有插件,但WooCommerce
  • 更改主题(尝试了所有标准的WordPress主题和一些WooThemes主题无济于事)
  • 更新了WooCommerce(v 2.1.5)
  • 手动插入wp_postmeta添加元键_manage_stock并将其设置为no(正如我们所拥有的某些工作产品中所观察到的那样)
  • 手动插入wp_postmeta添加元键'_stock'并将其设置为0(正如我们所拥有的某些工作产品中所观察到的那样)
  • 比较点击更新按钮之前和之后产品的postmeta,观察是否有任何改变会导致问题...没有
  • 未启用缓存
  • 使用XDebug跟踪$available_variationsvariable.php中的class-wc-ajax.php变量 class-wc-product-variable.php$available_variations

调试时我注意到在variable.php变量工作的产品中包含2个填充了产品信息的数组,但是对于那些没有产品信息的产品,它是一个空数组(导致缺货)正在显示的消息由WC_Product_Variation Object ( [variation_id] => 1310 [parent] => WC_Product_Variable Object ( [children] => Array ( [0] => 1311 [1] => 1310 ) [total_stock] => [id] => 1308 [post] => WP_Post Object ( [ID] => 1308 [post_author] => 1 [post_date] => 2012-04-03 14:29:42 [post_date_gmt] => 2012-04-03 18:29:42 [post_content] => This audio presentation on homeschooling is a Basement Tape conversation on homeschooling. <h2>What are The Basement Tapes?</h2> <em>The Basement Tapes</em> are conversations between Dr. R.C. Sproul Jr., Rev. Laurence Windham, their friends and special guests, on subjects related to the “good life,” a simple, separate, and deliberate life, lived out for the glory of God and for the building of His Kingdom. You might even say that the Basement Tapes serve to help us develop a Christian worldview. Started in 2002, we now have over #140 conversations on all areas of life that we are seeking to think biblically about so that we might take dominion over them for the King and His kingdom. <strong>Format: Available in both CD and MP3</strong> <strong>Length: Sixty minutes</strong> [post_title] => Basement Tape #109: Homeschooling Redux [post_excerpt] => It's been 108 weeks since we last talked about the subject of homeschooling our children. Our tykes have grown into teenagers. What have we learned in the past nine years? What has changed? What remains the same is that homeschooling means discipleship; passing down your most important convictions to your children and teaching them our holy religion. [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => bt0109-homeschooling-reducks [to_ping] => [pinged] => [post_modified] => 2014-07-07 11:08:46 [post_modified_gmt] => 2014-07-07 15:08:46 [post_content_filtered] => [post_parent] => 0 [guid] => http://50.57.190.158/?post_type=product&#038;p=1308 [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => variable ) [variation_data] => Array ( [attribute_pa_audio-options] => mp3-download ) [variation_has_length] => [variation_has_width] => [variation_has_height] => [variation_has_weight] => [variation_has_stock] => [variation_has_sku] => 1 [variation_shipping_class] => [variation_shipping_class_id] => [variation_has_tax_class] => [variation_has_downloadable_files] => 1 [id] => 1308 [post] => WP_Post Object ( [ID] => 1308 [post_author] => 1 [post_date] => 2012-04-03 14:29:42 [post_date_gmt] => 2012-04-03 18:29:42 [post_content] => This audio presentation on homeschooling is a Basement Tape conversation on homeschooling. <h2>What are The Basement Tapes?</h2> <em>The Basement Tapes</em> are conversations between Dr. R.C. Sproul Jr., Rev. Laurence Windham, their friends and special guests, on subjects related to the “good life,” a simple, separate, and deliberate life, lived out for the glory of God and for the building of His Kingdom. You might even say that the Basement Tapes serve to help us develop a Christian worldview. Started in 2002, we now have over #140 conversations on all areas of life that we are seeking to think biblically about so that we might take dominion over them for the King and His kingdom. <strong>Format: Available in both CD and MP3</strong> <strong>Length: Sixty minutes</strong> [post_title] => Basement Tape #109: Homeschooling Redux [post_excerpt] => It's been 108 weeks since we last talked about the subject of homeschooling our children. Our tykes have grown into teenagers. What have we learned in the past nine years? What has changed? What remains the same is that homeschooling means discipleship; passing down your most important convictions to your children and teaching them our holy religion. [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => bt0109-homeschooling-reducks [to_ping] => [pinged] => [post_modified] => 2014-07-07 11:08:46 [post_modified_gmt] => 2014-07-07 15:08:46 [post_content_filtered] => [post_parent] => 0 [guid] => http://50.57.190.158/?post_type=product&#038;p=1308 [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => variation [product_custom_fields] => Array ( [_sku] => Array ( [0] => BT0109MP3 ) [_price] => Array ( [0] => 3 ) [_sale_price] => Array ( [0] => ) [_weight] => Array ( [0] => ) [_length] => Array ( [0] => ) [_width] => Array ( [0] => ) [_height] => Array ( [0] => ) [_stock] => Array ( [0] => ) [_thumbnail_id] => Array ( [0] => 0 ) [_virtual] => Array ( [0] => yes ) [_downloadable] => Array ( [0] => yes ) [_download_limit] => Array ( [0] => ) [_downloadable_files] => Array ( [0] => a:1:{s:32:"a0a87d43e69ed9de646ba479c252c9fb";a:2:{s:4:"name";s:29:"109-Homeschooling-Reducks.mp3";s:4:"file";s:113:"http://highlandsministriesonline.org/wp-content/uploads/woocommerce_uploads/2012/04/109-Homeschooling-Reducks.mp3";}} ) [_regular_price] => Array ( [0] => 3 ) [_sale_price_dates_from] => Array ( [0] => ) [_sale_price_dates_to] => Array ( [0] => ) [_download_expiry] => Array ( [0] => ) [attribute_pa_audio-options] => Array ( [0] => mp3-download ) ) [sku] => BT0109MP3 [downloadable_files] => a:1:{s:32:"a0a87d43e69ed9de646ba479c252c9fb";a:2:{s:4:"name";s:29:"109-Homeschooling-Reducks.mp3";s:4:"file";s:113:"http://highlandsministriesonline.org/wp-content/uploads/woocommerce_uploads/2012/04/109-Homeschooling-Reducks.mp3";}} [downloadable] => yes [virtual] => yes [sale_price_dates_from] => [sale_price_dates_to] => [price] => 3 [regular_price] => 3 [sale_price] => [total_stock] => 0 [dimensions] => ) 提供。单击更新按钮然后跟踪变量会正确显示信息。

老实说,此时我很茫然。我认为问题出现在任何一个类中,但我无法分辨。

还有其他人有此问题吗?任何解决此问题的方法,所以我不必为这个客户端不断更新产品。

链接到缺货产品(截至发布时)http://highlandsministriesonline.org/product/basement-tapes/resentment-in-the-church-135/

链接到正确显示的产品http://highlandsministriesonline.org/product/basement-tapes/bt0111-church-at-corinth-i/

错误记录 我在产品变体类中添加了一个错误日志。结果如下:

对于“缺货”消息的产品,日志中不显示任何内容。

正常运行的产品示例:

{{1}}

潜在的后续步骤我的下一个想法是,如果我无法解决这个问题,那就是编写一个脚本,每晚会通过并更新网站上的每个产品(因为临时修复似乎有效)至少24我们的)。虽然如果我可以节省一些时间,我宁可不要,如果其他人能够永久解决这个问题。

截至2014年10月23日更新

尽管尝试以下答案,此问题仍然存在。我创建了一个日志插件,希望有助于跟踪缺货消息的频率,并希望有助于将消息与网站上发生的任何操作相关联。它目前是针对这个特定的网站定制的,但我正在开发一个版本与大家分享,所以即使我找不到答案,也有人可以。

9 个答案:

答案 0 :(得分:6)

我有同样的问题,我想我想出来了。我使用CSV导入/导出套件导出我的所有变体。您会注意到,当库存的值为0时,库存设置为null

这里有两个选项:

  1. 进入每个单独的产品,点击变体标签并展开每个变体 - 取消选中&#34;管理库存&#34;复选框:enter image description here
  2. 您可以在数据库上执行查找和替换,将0值替换为null。

答案 1 :(得分:4)

这是2017年,我仍然看到OP在商店运行中的确切问题:

  • WordPress 4.8.1
  • WooCommerce 3.1.2
  • PHP 5.6
  • 吨插件和janky主题

我没有时间真正修复错误 - 无论是什么 - 但我做了一个解决方法。

问题在于$product缺少与变体相关的所有内容。没有变体ID,属性或价格。我的解决方法在模板中使用之前修复了$product

第1步:将price.php模板复制到主题中。导航到/wp-content/plugins/woocommerce/templates/single-product/price.php的WooCommerce价格模板。将其复制到/wp-content/themes/my-theme/woocommerce/single-product/price.php的主题中。如果您已经拥有该文件,那么您已经有了自定义price.php模板,您可以跳过此步骤。

有关WooCommerce自定义模板如何工作的文档:https://docs.woocommerce.com/document/template-structure/

第2步:修改您刚刚放入主题的price.phpglobal $product;以下粘贴此内容:

if ( $product->is_type( 'variable' ) ) {
  // this is a variable product, so let's ensure $product is set up correctly

  // force the product to sync with its variations
  $product->sync( $product->id );
  // update $product with the synced product
  $pf = new WC_Product_Factory();
  $product = $pf->get_product( $product->id );
  // update utility variables used in the variable.php template
  $available_variations = $product->get_available_variations();
  $attributes = $product->get_variation_attributes();
}

我遇到了一些缓存问题,使其看起来好像最初没有工作。要测试它是否正常工作,你可以放弃

echo '<pre style="display: none;">';
print_r( $product );
echo '</pre>';

位于if的顶部和底部。现在您可以检查页面了,在价格之上将是修复之前和之后包含<pre>的两个隐藏的$product

这可以通过使用sync()函数强制产品获取所有缺失的变体信息,然后更新变量以在模板中使用来实现。我相信价格是最早在模板中使用的任何变体数据的价格,但如果需要,这个代码段可以轻松地在模板链中更高。

修改:以上修复仅适用于WooCommerce 3.x 。我确实为WC 2.x创建了一个修复程序,但它是如此巨大而且粗糙我不打算发布它。如果你还有一个2.x商店,你需要进行某种大修,以便你能够获得3.x.

答案 2 :(得分:4)

我在新创建的产品中遇到了同样的问题。但是对我来说答案很简单。

我需要为每个变化输入“常规价格”。
https://wordpress.org/support/topic/this-product-is-currently-out-of-stock-and-unavailable-4/

我以前创建了属性。

在变体下,对于我的产品,我必须确保选择了“添加变体”。然后,我单击“开始”按钮。

我需要为属性可能具有的每个不同选择创建一个变体。

因此,对于我的颜色选项,我必须进行三种不同的选择(每种选择一种)。
然后,我需要点击蓝色的“展开”文本,并确保每个变体的价格均为正常价格

然后它起作用了。 enter image description here

(这也很有帮助:https://docs.woocommerce.com/document/variable-product/

答案 3 :(得分:0)

尝试删除产品并创建相同的产品,并尝试我遇到同样的问题,它对我有用。甚至尝试重新安装WooCommerce 2.1.12

答案 4 :(得分:0)

这可能是产品的问题。尝试删除并重新添加产品或重新安装。

答案 5 :(得分:0)

我遇到了同样的问题,我想我找到了原因。 它与 WC_Product_Variable 类的 sync_stock_status 静态函数有关。

您可以在functions.php中修复运行此变量的产品库存状态: add_action('wp',function(){ $productId = 639; WC_Product_Variable::sync_stock_status(639); });

当然,这不是一个好的解决方案,因为它只能在一个特定时刻修复一个产品。

所以问题似乎是在适当的时候运行这个功能。

有趣的是我已经看过代码了,我发现快速编辑保存会调用此功能并修复产品!

其他有趣的事情是,似乎woocommerce团队可能已经将它修好了,因为我已经通过this commit发现他们现在在产品更新时调用此功能。

答案 6 :(得分:0)

编辑:我的问题再次出现-一段时间后,物品再次缺货。在四处搜索时,我发现wp_postmeta表中还有更多条目值得感谢post。在下面,我添加了2个其他更新功能,这些功能应有助于使该修复永远持续下去。

此问题的一个原因是,即使禁用了管理库存,库存状态也可能在数据库中记录为“缺货”。

您可以通过运行以下命令来检查phpMyAdmin中是否存在此问题:

UPDATE `wp_postmeta` SET `meta_value` = 'instock' WHERE `meta_key` = '_stock_status';
UPDATE `wp_postmeta` SET `meta_value` = '999999999' WHERE `meta_key` = '_stock';
UPDATE `wp_postmeta` SET `meta_value` = 'no' WHERE `meta_key` = '_manage_stock';

如果您看到项目“缺货”但预计将是“库存”,则可以手动更改它们。或者,您可以运行:

import sys, re
query = "![](images/folder0/subfolder1/file10.png)"
num = re.findall('\d+',query)[-1] # gives last number 0

newnum = int(num)+1
query = query.replace(r'file'+num, 'file'+str(newnum))
print(query)

答案 7 :(得分:0)

我遇到了同样的错误,并且在php.ini上更新了max_input_vars = 30000,并且工作正常。 我正在使用Siteground共享托管,

答案 8 :(得分:-1)

基于 WordPress woocommerce 的缺货产品消息显示并更改一些棘手的选项。如果您关心 wordpress 插件开发人员,您可以覆盖缺货挂钩。您也可以使用 wordpress 插件目录中已有的各种 wordpress 免费插件。

您可以使用“缺货消息”或“缺货消息 woocommerce”在谷歌搜索。

有一个很棒的插件可以解决缺货消息。插件链接 out of Stock message