Skip Navigation

[Resolved] wpv_filter_force_template doesn't run on my product category archive pages

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by caitlinC-3 2 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2125757

Hi. I'm dying here trying to get this to work: I read the other tickets that use wpv_filter_force_template to select different templates for a woocommerce archive page and it's not working for me. It doesn't appear to even run on the pages I need it on.

This is the code I'm trying to debug just to see why it doesn't work
***
add_filter( 'wpv_filter_force_template', 'func_assign_ct_dynamically', 10, 3 );
function func_assign_ct_dynamically( $template_selected, $post_id, $kind ) {

echo "Hi2";
echo $_SERVER['REQUEST_URI'];
if(str_contains($_SERVER['REQUEST_URI'], "product-category/shirts")) echo "This is in the shirts category";
//if(is_page(array( 'product-category/shirts', '/shirts/sam-winchester-shirts/', '/shirts/dean-winchester-shirts/' ))) echo "is shirts page";
if(is_shop()) echo "is Shop";
if(is_post_type_archive( 'product' )) echo "is_post_type_archive product";
if(is_product_category()) echo "Is product cat";
if(is_product()) echo "Is product";
flush();
if( is_product_category('shirts')) {
echo "Yes!";
$template_selected = 3498;
}
return $template_selected;
}
***

So this outputs the Hi2 and the url on regular pages.
hidden link
It outputs both those and "Is product" an odd number of times on the product pages, like it runs three times there
hidden link

But on the pages I am trying to actually use it on I can't see that it ever runs.
hidden link
hidden link

Those are category archive pages. I want to switch between templates I've built but the code doesn't ever appear to get called on those pages, how do I do this? Thanks.
I am able to create a single wordpress archive page and assign it to products in the toolset area, but that's not what I want, I want a top level one for the "shop" page and a couple different ones that I toggle between based on the category they pick.

Thanks.

#2126405

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

Your observation is correct and the filter "wpv_filter_force_template" only works for overriding the content templates and not the WordPress Archives:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

To programmatically override the WordPress Archives, you can use the filter "wpv_filter_force_wordpress_archive":
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive

Note: If you're using the Blocks editor for creating the WordPress Archives, you can also assign the different archives for different terms, without needing the custom code:
https://toolset.com/lesson-placement/lesson-placements-1621271-1622285/#assign-archives-to-specific-taxonomy-terms

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2127073

YASSSS THANK YOU 😀

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.