Skip Navigation

[Resolved] Using different layouts based on different woocommerce product categories

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

Problem:
Using different layouts based on different woocommerce product categories

Solution:
You can use the layouts filter "get_layout_id_for_render" to display the different layout per taxonomy term or category.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/using-different-layouts-based-on-different-woocommerce-product-categories/#post-1176756

Relevant Documentation:

This support ticket is created 5 years, 11 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.

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

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by kellyM-2 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1176711

Would it be possible to use a different layout based on the the woocommerce product category?

If I have a vehicle category (product_cat&tag_ID=105), I want to use a vehicle layout (ID 995)
If I have a parts category (everything else at this point), I want to use a parts layout (ID 883)

I looked here:
https://toolset.com/forums/topic/different-layout-for-post-category/ which is so close..

hidden link work in progress.

#1176756

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes, you can use the same code with some adjustment as per your requirement to assign different layout per product category.

For example - considering you want to apply this on single product pages.:

function apply_layout_by_post_term( $id, $layout ){
  global $post;

if(!is_singular('product')) return $id; 

 $vehicle_layout = 995;
 $parts_layout = 883;

  if( has_term(105, 'product_cat', $post->ID ) ){
      return $vehicle_layout;
  }else{
     return $parts_layout;
}
 
  return $id;
} 
add_filter('get_layout_id_for_render', 'apply_layout_by_post_term', 10, 2);
#1178228

'Please check the layout you are trying to render actually exists.'

Is the error I get when applying the code.

#1178229

Double checked. I made a typo in category. the Layout should be 945 not 995. I edited it and it appears to be working properly now. Thank you.

#1178230

My issue is resolved now. Thank you!