首页 文章

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

提问于
浏览
37

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

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

The thing is that we don't have inventory tracking turned on, all products should be in stock all the time.

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

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

Site Details:

  • 使用WordPress 3.9.1

  • WooCommerce 2.1.12

  • PHP 5.3.10(也在本地尝试使用5.5.10)

What I've tried

  • 删除所有插件但WooCommerce

  • 更改主题(尝试了所有标准的WordPress主题和一些WooThemes主题无济于事)

  • 更新了WooCommerce(它是v 2.1.5)

  • 手动插入wp_postmeta添加元键 _manage_stock 并将其设置为 no (在我们的一些工作产品中观察到)

  • 手动插入wp_postmeta添加元键'_stock'并将其设置为 0 (在我们的一些工作产品中观察到)

  • 比较点击更新按钮之前和之后产品的postmeta,观察是否有任何改变会导致问题...没有

  • 未启用缓存

  • 使用XDebug跟踪 variable.phpclass-wc-ajax.phpclass-wc-product-variable.php 中的 $available_variations 变量 .

在调试时我发现在正在运行的产品中, $available_variations 变量包含2个填充了产品信息的数组,但是在没有产品信息的产品上,它是一个空数组(导致缺货信息显示为 variable.php 服务) ) . 单击更新按钮然后跟踪变量可正确显示信息 .

老实说,在这一点上,我很茫然 . 我认为这个问题出现在任何一个类中,但我无法分辨 .

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

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

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

Error Log 我在产品变体类中添加了错误日志 . 下面是结果:

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

正常运行的产品示例:

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

Potential Next Steps 我的下一个想法是,如果我不能解决这个问题,那就是编写一个脚本,每晚会通过并更新网站上的每个产品(因为临时修复似乎适用于我们的至少24个) . 虽然如果我可以节省一些时间,我宁可不要,如果其他人能够永久解决这个问题 .

Update as of October 23,2014

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

6 回答

  • 0

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

    你有两个选择:

    • 进入每个产品,点击变体标签并展开每个变体 - 取消选中"manage stock"复选框:
      enter image description here

    • 您可以在数据库上执行查找和替换,将0值替换为null .

  • 5

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

    • WordPress 4.8.1

    • WooCommerce 3.1.2

    • PHP 5.6

    • 吨插件和一个janky主题

    我没有时间真正修复错误 - 不管它是什么 - 但我做了一个解决方法 .

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

    Step 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/

    Step 2 :编辑你刚刚放入主题的 price.php . 低于 global $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() 函数强制产品获取所有缺少的变体信息,然后更新变量以在模板中使用 . 我相信价格是最早在模板中使用的任何变体数据的价格,但如果需要,此片段可以轻松地在模板链中更高 .

    编辑: The above fix only works for WooCommerce 3.x . 我确实为WC 2.x创建了一个修复程序,但它是如此巨大而且粗糙我不打算发布它 . 如果你还有一个2.x商店,你需要进行某种大修,以便你能够获得3.x.

  • 0

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

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

    我以前创建过我的属性 .

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

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

    所以对于我的色彩选项,我必须做出三种不同的变化(每种选择一种) .
    然后我需要单击蓝色的“展开”文本和 make sure each variation had a Regular price .

    然后它奏效了 .
    enter image description here

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

  • 2

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

  • 0

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

  • 3

    我遇到了同样的问题,我认为've found the reason. It'与 WC_Product_Variable 类的 sync_stock_status 静态函数有关 .

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

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

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

    有趣的是我通过代码看到了,我发现 quick edit save 调用了这个函数并修复了产品!

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

相关问题