私は同じような別の質問があることを知っていますが、私の問題は奇妙に見えます。私は、PHPスクリプトを実行している、とのようなエラーを得続けるのです:
注意:未定義の変数を:PRODUCT_IDをDに:\ MY-WEBSERVER \ InstantWP_4.3.1 \ iwpserver \ htdocsに\ワードプレス\ WP-コンテンツ\テーマ\ MYTHEME \ライン上のfunctions.php 580
ライン580は、次のようになります。ここでは
if (wc_customer_bought_product($current_user->user_email, $current_user->ID, $product_id)) echo '<div class="user-bought">♥ Hey ' . $current_user->first_name . ', you\'ve purchased this in the past. Buy again?</div>';
フルコード:
add_action ('woocommerce_after_shop_loop_item',
'user_logged_in_product_already_bought', 30);
function user_logged_in_product_already_bought() {
if (is_user_logged_in()) {
global $product;
$current_user = wp_get_current_user();
if (wc_customer_bought_product($current_user->user_email, $current_user->ID, $product_id)) echo '<div class="user-bought">♥ Hey ' . $current_user->first_name . ', you\'ve purchased this in the past. Buy again?
</div>';
}
}
?>
これらの通知を解決するためのクイックフィックスはありますか? 本当に
は、この関数はWooCommerce 3+での作業を取得するための正しい方法があるあなたに
いいえ、何も '$のproduct_id'は、関数のスコープで定義されていません' user_logged_in_product_already_bought() '、奇妙な、標準的なコーディングエラーではありません。 – Scuzzy
https://businessbloomer.com/woocommerce-check-current-user-already-purchased-product/からコードをコピー&ペーストしようとしましたが、product_idが不正です。代わりに '$ product-> id'を使用してください – Scuzzy
あいまいさ:はい、私はそれらからコードを使用しています。 Woocommerceが更新される前の古いコード。 –