web-dev-qa-db-ja.com

WooCommerce製品が実際に在庫切れでない場合に「在庫切れ」メッセージを表示する

製品がランダムに表示されるクライアントWebサイトに問題がある

「この製品は現在在庫がなく、利用できません。」

問題は、在庫追跡が有効になっていないことです。すべての製品は常に在庫があるはずです。

WordPress adminに移動し、製品の更新ボタンをクリックすると(何も変更せずに)、メッセージが消えて[カートに追加]ボタンが表示されます。残念ながら、この問題は今後これらの項目で繰り返され、修正するには製品を再度更新する必要があります(WooCommerce設定で[更新]をクリックしても一時的に問題が解決します)。

この問題を永久に修正して、それ自体が元に戻らないようにする方法を見つける必要があります。

サイトの詳細:

  • WordPress 3.9.1を使用
  • WooCommerce 2.1.12
  • PHP 5.3.10(5.5.10でローカルに試しました)

私が試したこと

  • WooCommerce以外のすべてのプラグインを削除する
  • テーマの変更(すべての標準WordPressテーマといくつかのWooThemesテーマを使用できないように試してみました)
  • WooCommerceの更新(v 2.1.5でした)
  • メタキー_manage_stockを追加してwp_postmetaに手動で挿入し、noに設定します(一部の作業製品で確認されています)
  • メタキー「_stock」を追加してwp_postmetaに手動で挿入し、0に設定します(一部の実際の製品で確認されています)
  • 更新ボタンをクリックする前と後の製品のポストメタを比較して、問題の原因となる変更があったかどうかを確認します...
  • キャッシュは有効になっていません
  • XDebugを使用して、$available_variationsおよびvariable.phpおよびclass-wc-ajax.phpclass-wc-product-variable.php変数を追跡しました。

デバッグ時に、動作している製品では$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/

エラーログ製品バリエーションクラスにエラーログを追加しました。結果は次のとおりです。

「在庫切れ」メッセージのある製品の場合、ログには何も表示されません。

正しく機能する製品の例:

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日現在の更新

以下の回答を試みたにもかかわらず、この問題は引き続き発生しています。在庫切れメッセージの頻度を追跡し、Webサイトで行われたアクションとメッセージを関連付けるのに役立つように、ロギングプラグインを作成しました。現在、この特定のWebサイトに合わせてカスタマイズされていますが、回答を見つけることができなくても誰かが見つけることができるように、すべてのユーザーと共有するバージョンに取り組んでいます。

39
Ian

私はこれと同じ問題を抱えていて、私はそれを理解したと思います。 CSVインポート/エクスポートスイートを使用して、すべてのバリエーションをエクスポートしました。 nullの値が必要な場合、stockは0に設定されていることがわかります。

ここには2つのオプションがあります。

  1. 個々の製品に移動し、[バリエーション]タブをクリックして、各バリエーションを展開します-[在庫管理]チェックボックスをオフにします。enter image description here
  2. NULLを0の値に置き換えて、データベースで検索と置換を実行できます。
6
Zach Russell

新しく作成した製品でも同じ問題が発生していました。しかし、私にとって答えはもっと簡単でした。

バリエーションごとに「通常価格」を入力する必要がありました。
https://wordpress.org/support/topic/this-product-is-currently-out-of-stock-and-unavailable-4/

以前に属性を作成していました。

バリエーションの下で、私の製品では、「バリエーションを追加」が選択されていることを確認する必要がありました。次に、「実行」ボタンをクリックしました。

属性が持つ可能性のあるさまざまな選択肢ごとにバリエーションを作成する必要がありました。

そのため、色のオプションについては、3つの異なるバリエーション(選択ごとに1つ)を作成する必要がありました。
次に、青い「Expand」テキストをクリックして、各バリエーションに通常価格が設定されていることを確認するが必要です。

それはうまくいきました。 enter image description here

(これも役に立ちました: https://docs.woocommerce.com/document/variable-product/

4
Joe

それは2017年であり、私はまだ実行中のストアでOPの正確な問題を見ています:

  • WordPress 4.8.1
  • WooCommerce 3.1.2
  • PHP 5.6
  • たくさんのプラグインとジャンキーなテーマ

バグを(それが何であれ)本当に修正する時間はありませんが、回避策を作成しました。

問題は、_$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.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>_を含む2つの隠された_$product_があります。

これは、sync()関数を使用して、不足しているすべてのバリエーション情報を製品に取得させ、テンプレートで使用する変数を更新することで機能します。価格はテンプレートで使用されるバリエーションデータの中で最も早いと思いますが、このスニペットは必要に応じてテンプレートチェーンの上位に簡単に移動できます。

編集:上記の修正は、WooCommerce 3.xでのみ機能します。 WC 2.xの修正プログラムを作成しましたが、非常に大きくて大げさなので、投稿しません。 2.xストアがまだある場合は、3.xを使用できるようにするための何らかのオーバーホールを検討する必要があります。

4
pants

私は同じ問題を経験しており、その理由を見つけたと思います。これは、sync_stock_status静的関数WC_Product_Variableクラスに関連しています。

Functions.phpでこれを実行している可変製品在庫ステータスを修正できます:add_action('wp',function(){ $productId = 639; WC_Product_Variable::sync_stock_status(639); });

もちろん、特定の瞬間に1つの製品しか修正しないため、これは良い解決策ではありません。

したがって、問題はこの関数を適切なタイミングで実行しているようです。

おもしろいのは、コードを見て、クイック編集saveがこの関数を呼び出し、製品も修正することです!

他の興味深い点は、製品が更新されたときに、この機能を呼び出していることを this commit で確認したため、woocommerceチームがそれを永久に修正した可能性があることです。

0

製品の問題である可能性があります。製品を削除して再度追加するか、再インストールしてください。

0
DPC

製品を削除して同じ製品を作成してみてください。同じ問題が発生しましたが、うまくいきました。 WooCommerce 2.1.12を再インストールしてみてください

0
O-mkar