I've got WordPress site for which I've set up a custom post_type along with some custom fields created with CMB2 to display extra stuff within my custom posts.
When editing a single item for my custom post_type, it has a repeatable fields group set up in order to store prices and additional info, those are the fields:
price_tag
, product_title
, promo_desc
, promo_price
, check_promo
// All fields exist within the CMB2 repeatable group, what increases the level of difficult for a new comer to php development like me...
What I need is a correct logic to output the promo_price
field only if the checkbox field check_promo
value = yes, if = no, then does not display/echo the promo_price
field's value, then continue the logic to output the promo_price
field's value only if is a specific day of the week, in this case, I thought that perhaps the WordPress Codex for Formatting Date and Time might help...
This is how I'm trying to retrieve and display them:
$foodPrices = get_post_meta( $post->ID, '_prefix_food_price_group', true ); // repeatable fields group
// A checkbox "Show promo prices?" with values no, yes exists within the metabox _prefix_food_price_group
$promoDay = date('l'); // returns Sunday
<?php
foreach( (array) $foodPrices as $key => $value ){
if(!( isset( $value['price_tag'] ) ))
continue;
echo '<div class="col-xs-12 col-md-4">';
echo '<div id="price-box" class="panel">';
echo '<div class="panel-heading text-center">';
echo '<div id="prices-current">';
echo ' '. $value['price_tag'] .' ';
// if is Sunday
if ( $promoDay == 'Sunday') {
// display promo price if checkbox value =yes
if( in_array( 'yes', $foodPrices ) ) {
echo ' '. $value['promo_price'] .' ';
}
}
echo '</div>';
echo '<p>Serve de 1 a 2 pessoas</p>';
echo '</div>';
echo '<div class="panel-footer">';
if(!( isset( $value['price_title'] ) ))
continue;
echo '<div id="pricetitle" class="col-xs-6 text-center">' . $value['price_title'] . '</div>';
if(!( isset( $value['price_desc'] ) ))
continue;
echo '<div id="pricedesc" class="col-xs-6 text-center">' . $value['price_desc'] . '</div>';
echo '<div class="clearfix">';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
?>
So far everything works as intended, I can successfully display the fields on my theme template. However, it seems I'm not looping correctly through the repeatable fields and/or setting the right logic in order to achieve this.
Any help is very much appreciated.
$PromoPrice
?