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’ );

woocommerce_product_loop_start();

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

while ( $the_query->have_posts() ) :

$the_query->the_post();

wc_get_template_part( ‘content’, ‘productloop’ );

endwhile;

echo ‘</div>’;

woocommerce_product_loop_end();

do_action( ‘woocommerce_after_shop_loop’ );

else :

//do_action( ‘woocommerce_no_products_found’ );

endif;

wp_die();

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:

woocommerce_product_loop_end();

Which works and creates the closing part of the loop.

However adapting the after shop loop to:

woocommerce_after_shop_loop();

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 *