我正尝试通过以下方式向我的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;}
但是我不知道此代码是否正确,建议会有所帮助。
答案 0 :(得分:0)
wc_customer_bought_product()函数中缺少产品ID参数,您可以更轻松地获得WP_User
对象。这是一个用法示例:
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>';
}