[英]Add a purchase condition to WooCommerce products
我正在嘗試使用以下內容向我的 WooCommerce 產品添加購買條件:
{$current_user = wp_get_current_user();
if ( current_user_can('administrator') || wc_customer_bought_product($current_user->email, $current_user->ID,
// return true
return true;}
但我不知道這段代碼是否正確,建議會有所幫助。
wc_customer_bought_product() function 中缺少產品 ID 參數,您可以更輕松地獲得WP_User
object。 這是一個使用示例:
global $current_user;
if ( is_user_logged_in() && wc_customer_bought_product( $current_user->email, $current_user->ID, get_the_id() ) ) {
// Do something
echo '<p>' . __("You have already purchased this product before") . '</p>';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.