How to run WooCommerce pagination from within functions.php

I am building a very elaborate pagination script, the only piece I am missing is having the ability to run the in-built pagination from within the functions.php file.

While within the functions.php file. How can I build the pagination?

I use this code within the functions.php file:

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :

// do_action( ‘woocommerce_before_shop_loop’ );


echo ‘<div id=”product-list”>’;

while ( $the_query->have_posts() ) :


wc_get_template_part( ‘content’, ‘productloop’ );


echo ‘</div>’;


do_action( ‘woocommerce_after_shop_loop’ );

else :

//do_action( ‘woocommerce_no_products_found’ );



Where the query is a success, everything goes to plan. I get a list of all the items I search for. But the pagination is not built.

If I was to run this line outside the functions.php it will build it:

do_action( ‘woocommerce_after_shop_loop’ );

I imagine it would be something similar to the other snippets used in the query like this one:


Which works and creates the closing part of the loop.

However adapting the after shop loop to:


Yields errors: /admin-ajax.php 500 (Internal Server Error)

Please can someone direct me towards the correct initiating snippet I require to run pagination from within the wp_query inside the functions.php file?

Thanks to all contributors, I appreciate the question is vague, but I am just looking for a one line answer, Jason.

Read more here:: How to run WooCommerce pagination from within functions.php

Leave a Reply

Your email address will not be published. Required fields are marked *