您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

检查客户是否已经在WooCommerce中购买了商品

检查客户是否已经在WooCommerce中购买了商品

创建一个 当 且状态 时 该 。

这是此条件函数代码

function has_bought() {
    // Get all customer orders
    $customer_orders = get_posts( array(
        'numberposts' => -1,
        'Meta_key'    => '_customer_user',
        'Meta_value'  => get_current_user_id(),
        'post_type'   => 'shop_order', // WC orders post type
        'post_status' => 'wc-completed' // Only orders with status "completed"
    ) );

    // return "true" when customer has already at least one order (false if not)
   return count($customer_orders) > 0 ? true : false; 
}

这段代码在您的活动子主题主题的function.PHP文件中,或在插件PHP文件中。

其他 2022/1/1 18:15:16 有485人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶