Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter digidoda

    (@digidoda)

    I have also now tried it with just those 3 sections of code added and on the checkout page it is still showing as the whole number – is there a way of setting the digital wallet topup increment values to be 0.99 rather than 1 instead?

    Thread Starter digidoda

    (@digidoda)

    Thanks Subrata – do I need to remove the rest of the code that I provided too or is this just replacing the first 3 sections of the code I provided?

    I have tried replacing the first three sections and the wallet topup is still rounding up to £25 when it should actually be £24.75

    Thanks, Mike.

    Thread Starter digidoda

    (@digidoda)

    Thanks for replying Subrata – the code on the site is:

    add_action(‘wp_loaded’, function () {
    if (isset($_GET[‘wallet-topup’])) {
    $userId = get_current_user_id();
    $cart = [];
    foreach (WC()->cart->get_cart() as $item) {
    array_push($cart, [
    ‘product’ => $item[‘product_id’],
    ‘quantity’ => $item[‘quantity’]
    ]);
    }
    update_user_meta($userId, ‘wallet_cart’, $cart);
    $cartTotal = WC()->cart->get_cart_contents_total();
    $quantity = round($cartTotal / 0.99);
    WC()->cart->empty_cart();
    $product = get_wallet_rechargeable_product();
    WC()->cart->add_to_cart($product->get_id(), $quantity);
    wp_redirect(wc_get_checkout_url());
    exit;
    }

    if (isset($_GET['wallet-add-products-to-cart'])) {
        $userId = get_current_user_id();
        $cart = get_user_meta($userId, 'wallet_cart', true);
        foreach ($cart as $item) {
            WC()->cart->add_to_cart($item['product'], $item['quantity']); 
        }
        wp_redirect(wc_get_checkout_url());
        exit;
    }

    });

    add_action(‘woocommerce_after_checkout_validation’, function ($fields, $errors) {
    $product = get_wallet_rechargeable_product();
    $topupWallet = false;
    foreach (WC()->cart->get_cart() as $item) {
    if ($item[‘product_id’] == $product->get_id()) {
    $topupWallet = true;
    }
    }
    if (!$topupWallet) {
    $userId = get_current_user_id();
    $cartTotal = WC()->cart->get_cart_contents_total();
    $userBalance = woo_wallet()->wallet->get_wallet_balance($userId, ‘edit’);
    if ($userBalance < $cartTotal) { $errors->add(‘validation’, ‘You do not currently have enough chips in your account, please top up your chips here‘);
    }
    }
    }, 10, 2);

    add_filter(‘woocommerce_add_cart_item_data’, function ($cartIitemData, $productId, $variationId, $quantity) {
    $product = get_wallet_rechargeable_product();
    if ($productId == $product->get_id()) {
    $cartItemData[‘recharge_amount’] = $quantity;
    }
    return $cartItemData;
    }, 10, 4);

    add_filter(‘woocommerce_available_payment_gateways’, function ($gateways) {
    if (is_admin()) {
    return $gateways;
    }
    $product = get_wallet_rechargeable_product();
    $topupWallet = false;
    foreach (WC()->cart->get_cart() as $item) {
    if ($item[‘product_id’] == $product->get_id()) {
    $topupWallet = true;
    }
    }
    if (!$topupWallet) {
    unset($gateways[‘stripe’]);
    }
    return $gateways;
    }, 10);

    add_action(‘woocommerce_thankyou’, function ($orderId) {
    $order = wc_get_order($orderId);
    if ($order->get_payment_method() != ‘wallet’) {
    ?>

    <?php
    }
    });

    Thread Starter digidoda

    (@digidoda)

    Thanks so much Tom – all sorted now after your reply.

Viewing 4 replies - 1 through 4 (of 4 total)