[plugin: WooCommerce] if upsells exist don't display related products
-
The ultimate goal is to modify the WooCommerce plugin to not display related products if up-sells exist. Woo randomly picks the “related products” from all of your products. so… there is a good chance that the “related products” aren’t related at all.
If one wants to go in and pick their own related-type products they can add the to the up-sells field in the product’s edit screen.
I don’t want to entirely remove or not display the related products function or div. I would, however, like the template to perform an if/else statement to conditionally display the related products.
If $upsells exist don't display $related else display $related
The code below is from: /wp-content/plugins/woocommerce/templates/single-product, where I believe the appropriate changes can be made. I just don’t know enough about php or the way Woo is put together to make the change without breaking something.
related.php:
<?php /** * Related Products * * @author WooThemes * @package WooCommerce/Templates * @version 1.6.4 */ global $product, $woocommerce_loop; $related = $product->get_related(); if ( sizeof($related) == 0 ) return; $args = apply_filters('woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related ) ); $products = new WP_Query( $args ); $woocommerce_loop['columns'] = $columns; if ( $products->have_posts() ) : ?> <div class="related products"> <h2><?php _e('Related Products', 'woocommerce'); ?></h2> <ul class="products"> <?php while ( $products->have_posts() ) : $products->the_post(); ?> <?php woocommerce_get_template_part( 'content', 'product' ); ?> <?php endwhile; // end of the loop. ?> </ul> </div> <?php endif; wp_reset_postdata();
up-sells.php:
<?php /** * Related Products * * @author WooThemes * @package WooCommerce/Templates * @version 1.6.4 */ global $product, $woocommerce_loop; $related = $product->get_related(); if ( sizeof($related) == 0 ) return; $args = apply_filters('woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related ) ); $products = new WP_Query( $args ); $woocommerce_loop['columns'] = $columns; if ( $products->have_posts() ) : ?> <div class="related products"> <h2><?php _e('Related Products', 'woocommerce'); ?></h2> <ul class="products"> <?php while ( $products->have_posts() ) : $products->the_post(); ?> <?php woocommerce_get_template_part( 'content', 'product' ); ?> <?php endwhile; // end of the loop. ?> </ul> </div> <?php endif; wp_reset_postdata();
- The topic ‘[plugin: WooCommerce] if upsells exist don't display related products’ is closed to new replies.