Home › Forums › Front-end Issues › Two IFs, one conflict › Reply To: Two IFs, one conflict
The Accessories are set using WooCommerce’s UpSells section. If there are no items in the UpSells, I still want the DOWNLOAD CATALOG to display.
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<h1 itemprop="name" class="product_title entry-title"><?php the_title(); ?></h1>
<?php
global $product, $woocommerce_loop;
$upsells = $product->get_upsells();
if ( sizeof( $upsells ) === 0 ) {
return;
}
$meta_query = WC()->query->get_meta_query();
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $upsells,
'post__not_in' => array( $product->id ),
'meta_query' => $meta_query
);
$products = new WP_Query( $args );
$woocommerce_loop['columns'] = $columns;
if ( $products->have_posts() ) : ?>
<div class="upsells products">
<a id="trigger" class="product btn"><?php _e( 'Accessories', 'woocommerce' ) ?> <span class="glyphicon glyphicon-chevron-down"> </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 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();
?>
What does work, but not layout I want, is to move the DOWNLOAD CATALOG link outside the loop. But then I would have to make modifications to my CSS to force the layout that I want if there was/wasn’t any Accessories to post.
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.