function sunshine_checkout_update_totals()
{
    global $current_user;
    if (is_user_logged_in()) {
        SunshineUser::update_user_meta('shipping_method', isset($_POST['shipping_method']) ? sanitize_text_field($_POST['shipping_method']) : '');
        SunshineUser::update_user_meta('use_credits', isset($_POST['use_credits']) ? 1 : '');
        SunshineUser::update_user_meta('billing_as_shipping', isset($_POST['billing_as_shipping']) ? sanitize_text_field($_POST['billing_as_shipping']) : '');
        SunshineUser::update_user_meta('shipping_country', sanitize_text_field($_POST['shipping_country']));
        SunshineUser::update_user_meta('shipping_state', sanitize_text_field($_POST['shipping_state']));
        SunshineUser::update_user_meta('country', sanitize_text_field($_POST['country']));
        SunshineUser::update_user_meta('state', sanitize_text_field($_POST['state']));
        if (isset($_POST['billing_as_shipping']) && $_POST['billing_as_shipping'] == 1) {
            if ($_POST['shipping_country']) {
                SunshineUser::update_user_meta('country', sanitize_text_field($_POST['shipping_country']));
                SunshineUser::update_user_meta('state', sanitize_text_field($_POST['shipping_state']));
            } else {
                SunshineUser::update_user_meta('shipping_country', sanitize_text_field($_POST['country']));
                SunshineUser::update_user_meta('shipping_state', sanitize_text_field($_POST['state']));
            }
        }
    } else {
        SunshineSession::instance()->billing_as_shipping = isset($_POST['billing_as_shipping']) ? sanitize_text_field($_POST['billing_as_shipping']) : '';
        SunshineSession::instance()->shipping_method = isset($_POST['shipping_method']) ? sanitize_text_field($_POST['shipping_method']) : '';
        SunshineSession::instance()->shipping_country = sanitize_text_field($_POST['shipping_country']);
        SunshineSession::instance()->shipping_state = sanitize_text_field($_POST['shipping_state']);
        SunshineSession::instance()->country = sanitize_text_field($_POST['country']);
        SunshineSession::instance()->state = sanitize_text_field($_POST['state']);
        if (isset($_POST['billing_as_shipping']) && $_POST['billing_as_shipping'] == 1) {
            if ($_POST['shipping_country']) {
                SunshineSession::instance()->country = sanitize_text_field($_POST['shipping_country']);
                SunshineSession::instance()->state = sanitize_text_field($_POST['shipping_state']);
            } else {
                SunshineSession::instance()->shipping_country = sanitize_text_field($_POST['country']);
                SunshineSession::instance()->shipping_state = sanitize_text_field($_POST['state']);
            }
        }
    }
    $sunshine = new Sunshine();
    $sunshine->shipping = new SunshineShipping();
    $sunshine->cart = new SunshineCart();
    if (isset($_POST['state'])) {
        if (isset($_POST['shipping_method'])) {
            $return['shipping_method'] = sanitize_text_field($_POST['shipping_method']);
        }
        $return['shipping'] = sunshine_money_format($sunshine->cart->shipping_method['cost'], false);
        $return['tax'] = sunshine_money_format($sunshine->cart->tax, false);
        $return['credits'] = '-' . sunshine_money_format($sunshine->cart->useable_credits, false);
        $return['total'] = sunshine_money_format($sunshine->cart->total, false);
        if ($sunshine->cart->total == 0) {
            $return['free'] = 1;
        }
    }
    die(json_encode($return));
}
 function toggle_use_credit()
 {
     global $current_user;
     if (SunshineUser::get_user_meta('use_credits')) {
         SunshineUser::update_user_meta('use_credits', '0');
         return '0';
     } else {
         SunshineUser::update_user_meta('use_credits', '1');
         return '1';
     }
 }