2017-10-23 11 views
1

WooCommerceでは私はBoss Learndashプラグインを使用していますが、このプラグインのテンプレートファイルplugins/boss-learndash/templates/learndash/single-sfwd-course.phpでは、コース/製品を購入したユーザーにもう一度ボタンを追加しようとしています。テンプレートのwc_customer_bought_product woocommerce関数を呼び出そうとしていますが、その関数を呼び出すことができないようです。サードパーティプラグインのWoocommerce wc_customer_bought_productメソッドを呼び出す

global $woocommerce;を追加してみましたが、wc->user->wc_customer_bought_productでも試しましたが、修正できませんでした。

私は間違っていますか?

答えて

1

wc_customer_bought_product()ファンクションは、任意のWooCommerceクラスのメソッドではありません。それは3つの引数$customer_email$user_id$product_idとちょうど条件関数です:

wc_customer_bought_product($customer_email, $user_id, $product_id); 

あなたは条件付き関数としてif文の中でそれを使用しますので、それは、ブールtrueまたはfalseを返します。

ユーザーIDと顧客の電子メールを取得するには、使用することができます。

// Get the current user data: 
$user = wp_get_current_user(); 
$user_id = $user->ID; // Get the user ID 
$customer_email = $user->user_email; // Get the user email 
// OR 
// $customer_email = get_user_meta($user->ID, 'billing_email', true); // Get the user billing email 

// The conditional function (example) 
// IMPORTANT: $product_id argument need to be defined 
if(wc_customer_bought_product($customer_email, $user_id, $product_id)) { 
    echo "Has bought the product"; 
} else { 
    echo "Has not bought the product yet"; 
} 
関連する問題