当前位置: 首页 > 知识库问答 >
问题:

WooCommerce产品在未实际缺货时显示“缺货”信息

慕仲渊
2023-03-14

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

“此产品目前缺货且不可用。”

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

当我进入WordPress管理员并单击产品的更新按钮(不做任何更改)时,消息就会消失,“添加到购物车”按钮会按原样显示。不幸的是,这个问题在将来会在这些项目上重复出现,为了解决这个问题,我必须再次更新产品(同时在WooCommerce设置中单击update可以暂时解决这个问题)。

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

网站详情:

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

我试过的

  • 删除除WooCommerce之外的所有插件
  • 更改主题(尝试了所有标准WordPress主题和一些WooThemes主题,但均无效)
  • 更新的WooCommerce(它是2.1.5版)
  • 手动插入wp_Posteta,添加元键\u manage_stock,并将其设置为no(正如我们在一些工作产品中观察到的那样)
  • 手动插入wp_Posteta,添加元键“_stock”,并将其设置为0(正如我们在一些工作产品中所观察到的)
  • 比较单击“更新”按钮前后产品的延迟时间,以观察是否有任何更改会导致问题。。。没什么
  • 没有打开缓存
  • 使用XDebug跟踪变量中的$available\u变量。php类wc ajax。php类wc产品变量。php

调试时,我注意到在使用$available\u variations的产品中,变量包含两个填充了产品信息的数组,但是在没有填充的产品中,它是一个空数组(这导致缺货消息显示为variable.php)。单击更新按钮,然后跟踪变量,正确显示信息。

老实说,在这一点上,我不知所措。我认为这个问题在两个班级的某个地方,但我不知道。

还有其他人对此有意见吗?任何方法都可以解决这个问题,这样我就不必为这个客户不断更新产品。

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

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

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

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

功能正确的产品示例:

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] => 
)

潜在的下一步如果我不能解决这个问题,我的下一个想法是写一个脚本,每天晚上在网站上浏览和更新每个产品(因为临时修复似乎至少对我们的24个产品有效)。虽然如果我能节省一些时间,但如果其他人能够永久解决这个问题,我宁愿不要。

截至2014年10月23日的更新

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


共有3个答案

乐正洲
2023-03-14

现在是2017年,我仍然看到OP在一家运营的商店中的确切问题:

  • WordPress4.8。1
  • 第3.1条。2
  • 菲律宾比索5.6
  • 成吨的插件和令人生厌的主题

我没有时间真正修复这个bug——不管它是什么——但我做了一个变通办法。

问题是$Products缺少与变化相关的所有内容。没有变化ID、属性或价格。在模板中使用之前,我的变通方法会修复$Products

第1步:复制price.php模板到您的主题。导航到您的WooCommerce的价格模板在/wp-Content/plugins/wooCommerce/模板/单一产品/price.php。将其复制到您的主题/wp-内容/主题/my-主题/wooCommerce/单一产品/price.php。如果您已经有了那个文件,那么您已经有了一个自定义price.php模板,您可以跳过这一步。

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

第二步:编辑价格。php您只需输入主题。低于global$产品 粘贴此:

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的顶部和底部。现在您可以查看页面,价格上方将隐藏两个

这是通过使用sync()函数强制产品获取所有缺少的变体信息,然后更新模板中使用的变量来实现的。我相信这个价格是模板中最早使用任何变化数据的价格,但是如果需要的话,这个片段可以很容易地在模板链中上升。

编辑:以上修复仅适用于WooCommerce 3. x。我确实为WC 2. x创建了一个修复程序,但它是如此巨大和恶心,我不会发布它。如果你仍然有一个2. x商店,你需要考虑一些大修,让你可以使用3. x。

孔嘉茂
2023-03-14

我新创造的产品也遇到了同样的问题。但对我来说,答案更简单。

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

我以前已经创建了我的属性。

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

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

因此,对于我的颜色选择,我必须做出三种不同的变化(每种选择一种)
然后我需要单击蓝色的“展开”文本,并确保每个变体都有一个固定的价格。

(这也很有帮助:html" target="_blank">https://docs.woocommerce.com/document/variable-product/ )

蒋典
2023-03-14

我也有同样的问题,我想我已经解决了。我使用CSV导入/导出套件导出我的所有变体。您会注意到,当stock的值应为null时,stock被设置为0

你有两个选择:

  1. 进入每个产品,单击变体选项卡并展开每个变体-取消选中“管理库存”复选框:
 类似资料:
  • 我有一个问题与Magento(CE1.9.0.1)和缺货产品显示在类别页面。配置看起来很好,我已经刷新了缓存,索引也是最新的。有一个配置,其中有一个简单的产品分配。可配置产品设置为管理库存,简单产品也设置为管理库存,数量为0,缺货。我有同样的设置在另一个Magento网站,当一个简单的产品被设置为0和缺货,可配置的产品将成为缺货,并不显示在类别上。 null null 简单产品(截图) 所有内容都

  • [编辑:它实际上是在functions.php中添加代码并省略代码WC文件中的更改时工作的。重要提示:它只在ONE属性存在时起作用。然而,当有2个属性(大小 由于2.0 WooCommerce要么隐藏缺货的产品变体(一个明显的问题,因为客户没有办法知道它们的存在),要么将它们显示为库存变体(也是一个问题,因为客户会系统地失望地发现变体是缺货的-点击购买后的股票)。 该线程包括一个灰色解决方案,以消

  • 在Woocommerce中,我试图使一个定制的div容器在可变产品的变体缺货时可见,但在缺货时可用。

  • 在WooCommerce with Contact Form 7插件中,我在单品页面上添加了一个表单,使用以下代码: 这种“缺货”表单只适用于简单的产品: 但对可变产品的“缺货”产品变体不起作用:

  • 我想在单产品页面上显示运输类,在从可变产品中选择一个产品之后。例如:我有一辆自行车有三种颜色(红、蓝、绿): 自行车红有航运类“免费送货” 蓝色自行车的运输类别为“额外交付” 绿色自行车的运输等级为“正常交付” 我感谢你的任何想法。

  • 所以我的木业商店发生了一件奇怪的事情。 现在,当一个单一的产品(没有变种)缺货,“数量”和“添加到购物车”按钮消失-这是我想要的。上面只显示“缺货”的标签。