2016-10-04 9 views
0

このワードプレスプラグインを持っているので、のフリーカムがダウンロードされたときに、「カートに追加」ボタンが隠れてダウンロードボタンが追加されます。woocommerce買収した商品機能をプラグインに追加する

しかし、私はこのプラグインにもう1つの機能を追加したいと思います。

私はwc_customer_bought_product($customer_email, $user_id, $the_product) woocommerce機能を使用しようとしています。

しかし、それは動作していないようです。

//Returns true if the product/variation is free, downloadable and vitual. 
//Added by me: OR return true too if product was bought 

function dfd_is_virtual_free_download_product($post) { 

    global $woocommerce, $product; 
    $user_id = get_current_user_id(); 
    $current_user= wp_get_current_user(); 
    $customer_email = $current_user->email; 
    $current_product = $product->id; 

    if (empty($post)) return false; 


    $the_product = get_product($post); 

    if (!$the_product) { 
     //its not a product or product not found 
     return false; 
    } 

    $is_virtual = $the_product->is_virtual(); 
    $price = $the_product->regular_price; 
    $sale_price = $the_product->sale_price; 
    $is_downloadable = $the_product->is_downloadable(); 

    if ($sale_price == "0" || $sale_price == "0.00" || wc_customer_bought_product($customer_email, $user_id, $current_product)){ 
     $price = $sale_price; 
    } 
    if($price == 0 && $is_virtual == 1 && $is_downloadable == 1){ 
     return true; 
    } 
    return false; 

} 

答えて

0

あなたのコードに間違いが見つかりました。 なぜIDを2回ゲットしていますか?

$user_id = get_current_user_id(); 
$current_user= wp_get_current_user(); 

の$ CURRENT_USERは既にこのプロパティを注入し、あなたは> ID

もう一つの問題は、この$ current_user->メール

//This is wrong 
$customer_email = $current_user->email; 

//This works 
$customer_email = $current_user->user_email; 

希望未定義のプロパティを呼び出している$ current_user-このように呼び出すことができます助けてください。

は、このように関数を呼び出すようにしてください:

wc_customer_bought_product($customer_email, (int)$user_id, (int)$current_product); 

あなたはより良い値またはちょうどデバッガについての情報を取得するために()のvar_dumpを使用するようにしてください。

+0

ありがとうございましたが、うまくいきませんでした。私はまだ同じ結果を得ています。 –

+0

私の回答を編集しました – barbocc

関連する問題