IF statement not working – Any suggestions?


So I have a function which counts the amount of customer orders.

I want to show a congratulations modal that appears when a customer hits a specific amount of orders.

All of my code is working fine, except when I add this part to the IF statement:

|| in_array($count, $the_digits) && isset( $_COOKIE['tier_advance'] ) && $_COOKIE['tier_advance'] !== $count )

The cookie is being saved properly, and when saved the number is saved as the current value of count. The idea is that the modal will only show if:

A) their current count is in $the_digits array & the cookie is not set.
B) their current count is in $the_digits array & the cookie IS set, however the cookies value does not equal their current order $count amount.

This is to prevent the modal showing after the initial display, but still allow it to show again if they hit the next $count amount to move to the next tier.

Can’t figure out what is wrong. Or perhaps there is a better way to do this. All help appreciated.

        $the_digits = ['3','5','15','30','50'];

        if ( in_array($count, $the_digits) && !isset( $_COOKIE[ 'tier_advance' ] ) || in_array($count, $the_digits) && isset( $_COOKIE['tier_advance'] ) && $_COOKIE['tier_advance'] !== $count )  {
                    jQuery(document).on("click", "#tier_confirm", function(){            
                        // Set a cookie
                        Cookies.set("tier_advance", "' . $count . '", { expires: 356 });

            <!-- BEGIN Share Modal -->
            <div class="modal fade" id="tier_advance" tabindex="-1" role="dialog">
              <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                  <div class="modal-header text-center">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                  <div class="modal-body text-center">
                  <p>You are now a <strong class="all-caps"> ' . $tier_name . ' </strong>tier customer!</p>
                  <p>Expect some dope rewards to start coming your way!</p>
                  <div class="modal-footer modal-footer-centered">
                    <button id="tier_confirm" type="button" class="btn btn-secondary" data-dismiss="modal">Awesome, thanks!</button>
            <!-- END Share Modal -->';

, , Colin G 1 year 2020-07-10T20:11:53-05:00 0 Answers 69 views 0

Leave an answer