Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Single Event Php Script

I'm building a form that a cashier will enter a dollar amount into. When they enter that dollar amount it will add 100 points to their account for every dollar spent. This is built on WordPress so you'll see I'm getting and updating this point value with update_user_meta(); and get_user_meta(); which are built into WordPress.

You'll see I have a bunch of if statements that fire when the user hits the different point levels. My question is how can I make those statements only appear the very first time they've gone over the point threshold?

<form method="post" action="">
$<input type="text" name="value">
<input type="submit">
</form>

<?php
$prev_total = get_user_meta(get_current_user_id(), mycred_default, true);
$add_total = (floor($_POST['value']) * 100);

$now_total = $prev_total + $add_total;
update_user_meta(get_current_user_id(), mycred_default, $now_total);
echo get_user_meta(get_current_user_id(), mycred_default, true);

if($now_total > 0 && $now_total < 2501){

    echo "<h2>Customer Get's A Free Small Cup or Cone of Custard: Next Level 5000 Points.</h2>";

} elseif($now_total > 4999 && $now_total < 7500){

    echo "<h2>Customer Get's A Free Medium Gelato: Next Level 7500 Points.</h2>";

} elseif($now_total > 7499 && $now_total < 10000){

    echo "<h2>Customer Get's A Free Brownie Blackout: Next Level 10,000 Points.</h2>";

} elseif($now_total > 9999 && $now_total < 15000){

    echo "<h2>Customer Get's A Free Large Milk Shake: Next Level 15,000 Points.</h2>";

} elseif($now_total > 14999 && $now_total < 20000){

    echo "<h2>Customer Get's A Free Pint of Custard: Next Level 20,000 Points.</h2>";

} elseif($now_total > 19999 && $now_total < 25000){

    echo "<h2>Customer Get's A Free Pint of Custard: Next Level 25,000 Points.</h2>";

} elseif($now_total > 24999 && $now_total < 35000){

    echo "<h2>Customer Get's A Free Round of Mini Golf: Next Level 35,000 Points.</h2>";

} elseif($now_total > 34999 && $now_total < 45000){

    echo "<h2>Customer Get's A Free Small Custard Cake: Next Level 45,000 Points.</h2>";

} elseif($now_total > 44999 && $now_total < 50000){

    echo "<h2>Customer Get's 20 Free Batting Cage Tokens: Next Level 50,000 Points.</h2>";

} elseif($now_total >= 50000){

    echo "<h2>Customer Get's 20 Free Batting Cage Tokens & 20 Free Batting Cage Tokens.</h2>";
    $now_total = 0;

}
?>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Using your existing code I would add another condition to the elseif's to check the previous total - something like

} elseif($prev_total < 5000 && $now_total > 4999 && $now_total < 7500){

So the next time they make a purchase the previous total value would be within these limits so it shouldn't hit until the next one.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda