Additional custom fields - if / Else Statement with the flag true / false

I added a true / false flag using additional custom fields for Wordpress. I want to be able to choose an option that modifies the page template.

I am adding this parameter to the product category in WooCommerce / Wordpress. I have included this bit of logic in the code.

I have the following code, but it does not work. I suspect this is because it is not in a loop. However, the code I want to insert includes a loop. Any ideas / recommendations on the code are greatly appreciated.

<?php if (is_product_category() && get_field('field_name') == true) { ?>

    <div class="custom-sidebar-right">
            <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php woocommerce_get_template_part( 'content', 'product' ); ?>                 
            <?php endwhile; // end of the loop. ?>

    </div>

<?php } elseif (is_product_category() && get_field('field_name') == false ) { // Added close brace

<div> Empty Test </div>
}
+4
source share
2 answers

, ACF (http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/)

, , . var_dump, .

// vars
$queried_object = get_queried_object(); 
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;  

$is_field_name = get_field('field_name', $taxonomy . '_' . $term_id);

if (is_product_category() && $is_field_name == false) { ?>
+2

if,

  if (is_product_category() && get_field('field_name') == true) 

if (is_product_category() && get_field('field_name') == true) )
0

All Articles