Hi again.
i want to show button on specific main category. Not on shop page or home page.
i tried the code attached. It show “Show all” but it happens nothing, it doesnt show then all products in specific category…
i used this code:
/**
* This will add a ‘Show All’ link after the pagination on the shop pages.
* It will be hidden once it is activated.
*/
add_action( ‘woocommerce_after_shop_loop’, ‘wpse333192_add_showall’, 40 );
function wpse333192_add_showall() {
if ( ! isset( $_GET[‘showall’] ) ) {
global $wp;
echo sprintf(
“%s“,
home_url( add_query_arg( array_merge( $_GET, [ ‘showall’ => 1 ] ), $wp->request ) ),
__( ‘Show All’, ‘text-domain’ )
);
}
}
/**
* This will alter the main product query if ‘showall’ is activated
*/
add_action( ‘pre_get_posts’, ‘wpse333192_alter_query_showall’ );
function wpse333192_alter_query_showall( $query ) {
/**
* Alter the query only if it is:
* 1. The main query
* 2. Post type is product
* 3. $_GET[‘showall’] is set
* 4. $_GET[‘showall’] equals 1
*/
if ( $query->is_main_query()
&& $query->get( ‘post_type’ ) == ‘product’
&& isset( $_GET[‘showall’] )
&& $_GET[‘showall’] == 1
) {
// Load the ‘first’ page
$query->set( ‘paged’, 1 );
// Set post per page to unlimited
$query->set( ‘posts_per_page’, – 1 );
}
return $query;
}