Add content in between product rows in WooCommerce archives

前端 未结 1 488
梦谈多话
梦谈多话 2020-12-12 01:28

I want to show some content after the third product (and maybe the sixth, ninth...) of a product category. Not every category has that extra content or the same amount of it

1条回答
  •  离开以前
    2020-12-12 01:38

    Updated - Instead of overriding a template file, you can use the following hooked function, that will add a custom content full row in between each products row:

    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 > 1 ) :
        
        ?>
        

    Code goes in functions.php file of your active child theme (or active theme). Tested and works.

0 讨论(0)
提交回复
热议问题