Woocommerce

Woocommerce 基础设定与相关函数代码

获取顾客总消费金额

这段代码定义了一个名为gk_get_customer_total_spent()的函数,用于获取当前登录用户在WooCommerce商店中的总消费金额。

//获取顾客总消费金额
function gk_get_customer_total_spent() {

    // 检查用户是否已登录
    if (!is_user_logged_in()) {
        return 0; // 如果未登录,返回0
    }
    
    // 获取当前用户ID
    $user_id = get_current_user_id();
    
    // 获取用户总消费金额
    $total_spent = wc_get_customer_total_spent($user_id);
    
    return $total_spent; // 返回总消费金额
}

获取顾客订单总数

这段代码定义了一个名为gk_get_customer_total_orders()的函数,用于获取当前登录用户在WooCommerce商店中的订单总数。

//获取顾客订单总数
function gk_get_customer_total_orders() {

    // 检查用户是否已登录
    if (!is_user_logged_in()) {
        return 0; // 如果未登录,返回0
    }
    
    // 获取当前用户ID
    $user_id = get_current_user_id();
    
    // 获取用户订单总数
    $order_count = wc_get_customer_order_count($user_id);
    
    return $order_count; // 返回订单总数
}

Related posts

Leave the first comment