WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Last product/category in loop (3 posts)

  1. 0li4tw
    Member
    Posted 1 year ago #

    Hello there,

    http://tp4x4.v2webdesign.co.uk/products/

    I'm wondering if it possible to find out when the category/product loop is the last.

    I'm in the process of building a customer template and to organise the products I am using a grid.

    This is in files: content-product-cat.php & content-product.php

    <?php if ($woocommerce_loop['loop']&1){ ?>
    	<div class="row product-grid-row"> <?php }?>
    		<div class="product-category product large-6 small-12 columns">
    
    content stuff is here
    
    		</div>
    	</div>
    <?php if ($woocommerce_loop['loop']&2) { ?></div><?php } ?>

    This code opens the .product-grid-row div for each odd number and closes it for each even number, creating 2 products per row.

    The problem is when the last product is an odd number or there is an odd number if products/categories.

    If there is a way to determine the number of categories/products in that loop I can simply use that variable:

    if ($lastinloop) echo "</div>";

    Any help would be greatly appreciated.

    Thanks,
    Oli

    http://wordpress.org/extend/plugins/woocommerce/

  2. jameskoster
    Member
    Plugin Author

    Posted 1 year ago #

    What did you want to do with the last product?

    To create rows of 2 you'd be better off using the loop_shop_columns filter;

    http://docs.woothemes.com/document/change-number-of-products-per-row/

    This will change the first/last class positions.

  3. 0li4tw
    Member
    Posted 1 year ago #

    Thanks for the reply.

    The problem is that I am using a responsive grid system that needs special classes, so each row needs to be surrounded by <div class="row"> </div>.

    I tried using the shop_columns feature before to tell the loop when to open the .row div, and also when to close it. This works fine for complete rows but the problem is (correct me if i'm wrong) it can't be used to close the <div class="row"> if it isn't the second loop of the column.

    Many thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic