Support

Account

Home Forums Front-end Issues Two IFs, one conflict Reply To: Two IFs, one conflict

  • @toad78

    Then you need to move the if statement or duplicate it like this:

    <div class="upsells products">
    
    	<a id="trigger" class="product btn"><?php _e( 'Accessories', 'woocommerce' ) ?> <span class="glyphicon glyphicon-chevron-down">&nbsp;</span></a>
          
    		<?php 
            
                    $file = get_field('catalog');
                    
                    if( $file ) {
                    
                        $url = wp_get_attachment_url( $file );
                        
                        ?><a id="catalog" target="_blank" class="product btn" href="<?php echo $url; ?>" >DOWNLOAD CATALOG</a><?php
                    
                    }
                    
                    ?>  
    	<?php if ( $products->have_posts() ) : ?>
    		<?php woocommerce_product_loop_start(); ?>
    
    			<?php while ( $products->have_posts() ) : $products->the_post(); ?>
    
    				<?php wc_get_template_part( 'content', 'accessories' ); ?>
    
    			<?php endwhile; // end of the loop. ?>
    
    		<?php woocommerce_product_loop_end(); ?>
    	<?php
    		endif;
    		wp_reset_postdata();
    	?>
            
    </div>

    Or this one:

    <?php if ( $products->have_posts() ) : ?>
    
     	<div class="upsells products">
    
    		<a id="trigger" class="product btn"><?php _e( 'Accessories', 'woocommerce' ) ?> <span class="glyphicon glyphicon-chevron-down">&nbsp;</span></a>
    		
    <?php endif; ?>
    		
    		<?php 
            
                    $file = get_field('catalog');
                    
                    if( $file ) {
                    
                        $url = wp_get_attachment_url( $file );
                        
                        ?><a id="catalog" target="_blank" class="product btn" href="<?php echo $url; ?>" >DOWNLOAD CATALOG</a><?php
                    
                    }
                    
                    ?>  
    <?php if ( $products->have_posts() ) : ?>
    		<?php woocommerce_product_loop_start(); ?>
    
    			<?php while ( $products->have_posts() ) : $products->the_post(); ?>
    
    				<?php wc_get_template_part( 'content', 'accessories' ); ?>
    
    			<?php endwhile; // end of the loop. ?>
    
    		<?php woocommerce_product_loop_end(); ?>
            
    	</div>  
    
    <?php
    endif;
    wp_reset_postdata();
    ?>

    Hope this makes sense.