Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
1
Indexable
add_action('woocommerce_account_dashboard', function(){
    $user_id = get_current_user_id();
    $is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
    if ($is_b2b === 'yes'){

        $subaccounts = b2bking()->get_user_subaccounts($user_id);

        $total_spent_all = 0;
        foreach ($subaccounts as $sub){
            $customer = new WC_Customer($sub);
            $total_spent = $customer->get_total_spent();
            $total_spent_all += $total_spent;
        }

        ?>
        Total spend of all accounts: <?php echo '<strong>'.wc_price($total_spent_all).'</strong><br>';

        $customer = new WC_Customer($user_id);
        $total_spent = $customer->get_total_spent();
        $current_user = wp_get_current_user();

        echo $current_user->user_login.': '.'<strong>'.wc_price($total_spent).'</strong><br>';

        foreach ($subaccounts as $sub){
            $customer = new WC_Customer($sub);
            $total_spent = $customer->get_total_spent();
            $user = new WP_User($sub);

            echo $user->user_login.': '.'<strong>'.wc_price($total_spent).'</strong><br>';
        } 

        ?>
        <?php

    }
});