0
所以我有這個wordpress插件,它自己隱藏'添加到購物車'按鈕並添加一個下載按鈕,當Woocommerce產品是免費的。將購買woocommerce產品功能添加到插件
但是我想添加另一個功能到這個插件,當產品已經被購買時應該做同樣的事情。
所以我試圖使用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;
}
感謝您的幫助,但它沒有奏效我仍然得到相同的結果。 –
我編輯了我的答案 – barbocc