Ecommerce Shopify WordPress Discussion

PHP comparing number fields not giving correct output

I have two meta fields in Wordpress (ACF) that track the score of our soccer games. It's a group field with a name of 'score' with two number fields in it, 'bucs' (that's us, the Bucs) and 'opp' for our opponent. I am able to assign the variables and display them easy enough with: $score = get_field('score'); $bucsscore = $score['bucs']; $oppscore = $score['opp']; echo $bucsscore; echo $oppscore; Now my goal is to assign a class to a div based on the game outcome: win, lose, tie. I am trying to get this class by simply comparing the two scores. What I have so far gives me inconsistent results on every game. Sometimes a 0 - 0 score says we lost. If we win 1 - 0 it says we tie. If we tie 1 - 1 it says we won. <?php if($bucscore === $oppscore) { echo 'tie-game'; } elseif ($bucscore < $oppscore) { echo 'lost-game'; } elseif ($bucscore > $oppscore) { echo 'won-game'; }?> I have tested the '===' with '=' and '==' and still get the same inconsistency. I am thinking I can reduce the amount of code if I could create a variable that gave me the class based on the comparison but I am stuck here for now.
In your code, it seems there's a typo in the variable name $bucscore. It should be $bucsscore. if ($bucsscore === $oppscore) { echo 'tie-game'; } elseif ($bucsscore < $oppscore) { echo 'lost-game'; } elseif ($bucsscore > $oppscore) { echo 'won-game'; }

February 17, 2024

This code works fine for me when just assigning numbers to the vars. Maybe there's something wonky with how the data is coming from ACF? Try a var_dump to see what actual datatypes you're getting from ACF: echo var_dump($bucscore); echo var_dump($oppscore);

February 17, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.