2017-10-23 19 views
1

WooCommerce에서 Boss Learndash 플러그인을 사용 중이며이 플러그인 plugins/boss-learndash/templates/learndash/single-sfwd-course.php의 템플릿 파일에서 코스/제품을 구매 한 사용자에게 한 번 더 버튼을 추가하려고합니다. 템플릿에 wc_customer_bought_product woocommerce 함수를 호출하려고 시도했지만 해당 함수를 호출 할 수없는 것처럼 보입니다.제 3 자 플러그인에서 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와 단지 조건부 기능 : 그것은 부울 true 또는 false 돌아갑니다

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

, 그래서 당신은 조건부 기능과 같은 if 문에서 사용됩니다.

사용자 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"; 
}