I would like to show some content after the fifth product of a product category.
Based on Add content in between product rows in WooCommerce archives answers code, I am using this slight modified version code:
add_action( 'woocommerce_shop_loop', 'action_woocommerce_shop_loop', 100 );
function action_woocommerce_shop_loop() {
// Only on producy cayegory archives
if ( is_product_category() ) :
global $wp_query;
// Get the number of columns set for this query
$columns = esc_attr( wc_get_loop_prop( 'columns' ) );
// Get the current post count
$current_post = $wp_query->current_post;
if ( ( $current_post % $columns ) == 0 && $current_post%6==0 ) :
?>
<div class="product-grid-item col-md-3 col-sm-4 col-xs-6"><div class="banner"><?php _e("Custom content here"); ?></div></div>
<?php
endif; endif;
}
This kind of works, but adds the custom content (DIVs) multiple times. It’s adding it every 6 columns. I just need one single DIV after the 6th column.
2
Answers
If you want to display the content just once after sixth column, just change the if condition to:
You can also insert the content after any number of posts by using this code: