Home › Forums › Front-end Issues › If statement for a false selection
I’m trying to hide a div if a true/false is un-checked or a date has passed from the date picker. I’ve got the date picker part working, but I can’t get the true/false bit to work.
From my limited php knowledge and reading the docs, I have this;
$false = get_field('deposit_required', false, false);
which is then used in this line of code;
<div <?php if($date_passed == "date-passed" || $false == 'true') echo 'class="display-none"'; ?> class="container " id="deposit_box">
I’m thinking its something really simple I’ve overlooked as looking at other threads, it seems a simple thing to achieve.
Thanks
Wayne
I’ve sorted this. For some reason the reply from @bentangible isn’t showing. This is what they wrote;
You might want to check out Loops & Logic for this, it makes this kind of thing relatively easy. It uses a syntax like HTML to achieve this kind of functionality instead of needing to work with PHP. So to achieve what you’re trying to do, you’d create a template that included some markup like I’ve written below, and then you’d display it on your page either using a shortcode or the block in the page builder you’re using:
<If acf_true_false=deposit_required>
<div class="container" id="deposit_box">
<!–your div content goes here and all this will be displayed if the deposit_required ACF true/false field is set to "true"–>
</div>
</If>
The nice thing about this approach is you’re not bloating the dom with display-none content, you’re actually not even rendering that whole div if the ACF true/false field is set to false. In my example above I assumed your field was called deposit_required but I’m not well-versed in PHP so I might have misinterpreted exactly what you’re trying to do. I just find it’s easier to work with L&L for this kind of thing where you just need to display some HTML data or conditionally show/hide stuff. Much easier to understand than PHP for me personally since it just uses regular HTML syntax.
I then ended with this;
<?php if ( get_field( 'deposit_required' ) ): ?>
<div <?php if($date_passed == "date-passed") echo 'class="display-none"'; ?> class="container " id="deposit_box">
<div class="row">
<div class="col-12">
<h3><?php the_field('deposit_box'); ?></h3>
<p>Phone <a href="tel:XXXXXXXXXXX">XXXXXXXXXX</a> or <a href="mailto:xxxxxxxxxxxxxxxxxx">email</a> to pay your deposit and book your place on the event.</p>
<p><strong>Non-refundable deposit option.</strong></p>
<p>XXXXXXX offer a non-refundable payment option on selected events of £45.00 and over. A 25% deposit is required at the time of booking with the remaining balance due no later than 3 weeks prior to the event.</p>
<p>Failure to pay on time will result in places cancelled without any refund offered and your deposit payment lost.</p>
</div>
</div>
</div>
<?php endif; ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.