Skip Navigation

[Resolved] AJAX pagination for Woocommerce featured products View

This thread is resolved. Here is a description of the problem and solution.

Problem:
I want to display a slideshow of WooCommerce featured products using a View with AJAX pagination. The View works fine, but the AJAX pagination doesn't function correctly.

Solution:
Use the Query filter button in the View to add the Product Visibility taxonomy filter with the value set to featured. Remove custom pagination code from Toolset settings. This resolves the issue by correctly displaying the featured products with AJAX pagination.

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-pagination/

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.39 hours from now. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by Christopher Amirian 4 months, 4 weeks ago.

Assisted by: Christopher Amirian.

Author
Posts
#2704827

Hi, I wanto to display a slideshow of Woocommerce featured products. I've built a View with AJAX pagination where I display 4 items per page.

I've added this hook to get the Woocommerce featured products:

add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {

if ($view_id == 4304){

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$query_args = array(
'post_type' => 'product',
'posts_per_page' => 4 ,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}

The View works fine, but not the AJAX pagination.

How can I fix it?

thanks
Umberto

#2705015

Christopher Amirian
Supporter

Languages: English (English )

Hi Umberto,

I am not sure if the pagination of Views will work with the pagination you have in the WordPress query in the hook.

What if you avoid having paged content in the WP Query and keep the agitation in the view. What happens then?

#2705018

Hi, if I remove the pagination from the hook, the view pagination still doesn't work. Actually, I've added it to the hook just to try it, but I first used the code without it.

Now I've tested with this code:

/* Featured products based on WooCommerce featured star */

add_filter( 'wpv_filter_query', 'featured_products',99,3 );
function featured_products( $query_args,$views_settings, $view_id) {

if ($view_id == 4304){

$query_args = array(
'post_type' => 'product'
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}

Same result. When I click on the pager arrow, it reload the same entries.

cheers

#2705407

Christopher Amirian
Supporter

Languages: English (English )

Hi Umberto,

Would you please get back to us with the URL/USER/PASS of your website after you copy the website to the staging version? So we can test things out without the fear of affecting a live website.

Also tell us the information below:

- Which view or page or content template you use
- The URL that it is used in.
- Where to see the code that you used.

Thanks.

#2705491

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the information. I went to the view in question and used the Query filter button there to add the filter.

I selected the Product Visibility taxonomy and in the filter value selected features.

I kept the rest of the pagination the same and I deactivated your custom code from Toolset Settings.

The result seems to be correct now. It has 5 featured items and as the pagination is set to 4 it shows 4 items and loads the other one later.

Thanks.

#2705494

Wow! That's so easy and cool!

There is no documentation about this. I discovered that Featured products are defined by Product Visibility taxonomy because I found the custom code on Toolset support. I didn't check for it in the view because I thought it was a "not accessible" WooCommerce's private taxonomy. I found the custom code solution in many support threats, so it seems it is the only solution.

thank you