I am using the Custom Fields Plugin and have 2 custom fields assigned to my "products" custom post type.
Field 1. Price
Field 2 Discount Price
So this is my code:
<div class="wrapper">
<p>Price: <?php the_field('price'); ?></p>
</div>
"Now this is what I am trying to achieve hypothetically"
<div class="wrapper">
<?php if (the_field('discount'); )is set: ?>
<p>Discount: <?php the_field('discount'); ?></p>
<?php endif; ?>
<?php else: ?>
<p>Price: <?php the_field('price'); ?></p>
</div><!--wrapper-end-->
<?php endif; ?>
I don't know if thats the best way to do what im trying to achieve but I am trying to only display a certain custom field and not the other depending on if one of them is set or not.
So this is really the logic thats giving me trouble:
if <?php the_field('discount'); ?> is set:
I have actually tried using :
<?php $values = get_post_custom_values("discount");
if ( is_array($values) ): ?>
<p>Discount: <?php the_field('discount'); ?></p>
<?php else: ?>
<p>Price: <?php the_field('price'); ?></p>
<?php endif; ?>
but did not seem to work when I had my price field set and not my discount field it just did not display anything. but if I had set a discount it would display.
Anyone have an idea?
UPDATE
So whenever I set my discount it would show, but when I did not have a discount my original price field didn't show. So that told me that there was something wrong with the else statement.
Never mind scratch that I I tried the code now the if statement is not working and only shows the else which is the price