向 WooCommerce 产品添加购买条件 [英] Add a purchase condition to WooCommerce products
本文介绍了向 WooCommerce 产品添加购买条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下内容向我的 WooCommerce 产品添加购买条件:
I ma trying to add a purchase condition to my WooCommerce products with the following:
{$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;}
但我不知道此代码是否正确,建议会有所帮助.
But I don't know if this code is correct and an advise will be helpful.
推荐答案
wc_customer_bought_product() 函数中缺少 product Id 参数,您可以更轻松地获取 WP_User
对象.这是一个用法示例:
The product Id argument is missing from wc_customer_bought_product() function, and you can get more easily the WP_User
object. Here is a usage example:
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>';
}
这篇关于向 WooCommerce 产品添加购买条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文