【问题标题】:Add a purchase condition to WooCommerce products向 WooCommerce 产品添加购买条件
【发布时间】:2020-06-03 12:31:21
【问题描述】:

我正在尝试使用以下内容向我的 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;}

但我不知道这段代码是否正确,建议会有所帮助。

【问题讨论】:

    标签: php wordpress woocommerce product user-data


    【解决方案1】:

    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>';
    }
    

    【讨论】:

      猜你喜欢
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2019-02-20
      • 2015-01-15
      • 1970-01-01
      • 2014-11-21
      • 2014-11-15
      相关资源
      最近更新 更多