• Resolved lucinda91

    (@lucinda91)


    Problems encountered) :

    I have an order form on which a credit number is deducted according to the following options:

    speed limit = 1 credit
    immobilizer = 2 credits
    Stop / Start = 2 credits
    NoX = 2 credits
    DTC = 1 credit
    Initially the cost of the order is 5 credits, and I currently have 18 credits, when I chose for example the first option to 1 credit, the result of the calculation is displayed well, ie the cost of the order goes to 6 credits, but the subtraction on the 18 credits currently on sale is not done, normally it should also show a balance of 12 credits instead of 18 since I make an order that costs 6 credits in total .

    Here is the linked code:

    <?php endwhile; ?>
    Total of order: <span class= “total”><?php echo $car->custom[‘prix’]; ?></span> credits
    <p>You have <span class= “solde”><?php echo get_the_author_meta( ‘credits’, $user->ID ) ?></span> credits</p>
    <?php acf_enqueue_uploader(); ?>

    I need help for days I’m looking for I can not find a solution.

    On the Net I found the following code, but not being a developer ??

    <?php
    $my_first_number= 3;
    $my_seconde_number = 4;
    $resultat = $my_first_number – $my_seconde_number;
    echo $resultat; //poster 3-4 ie -1
    ?>

    Thanks

    • This topic was modified 5 years, 9 months ago by lucinda91.
    • This topic was modified 5 years, 9 months ago by Jan Dembowski. Reason: Title de-capped. Don't yell

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The important part is that you need to save the new balance back to author meta so that the proper balance persists between requests. Be sure your code cannot execute twice for the same transaction or the user will be double debited points. I suggest something like this:

    <p>Initial balance: <?php $bal = get_the_author_meta( 'credits', $user->ID );
    echo "$bal</p>\n"; ?>
    Total of order: <span class= "total"><?php $debit = $car->custom[‘prix’];
    echo $debit;
    $bal -= $debit;
    update_user_meta( $user->ID, 'credits', $bal ); ?></span> credits
    <p>You have <span class= "solde"><?php echo $bal; ?></span> credits remaining</p>

    BTW, when you post code in these forums, please demarcate with backticks or use the code button. If you do not, the forum’s parser corrupts your code and makes it difficult to edit or test.

    Thread Starter lucinda91

    (@lucinda91)

    Thank you very much that’s exactly what I had to do ??
    Alright I’ll think about it next time for the code, thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘calculation subtraction of amount for remaining balance in php’ is closed to new replies.