Skip Navigation

[Resolved] dynamic single layout for products stopped working

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

This topic contains 1 reply, has 1 voice.

Last updated by Nashaat 2 years, 3 months ago.

Author
Posts
#2439167

Hi,

I had 3 Single Layouts for products. Each Layout has custom design depending on the product category .

Now since i started to modify some elements in each Layout, each product regardless the category is showing now only one single layout design ignoring the function i have got from the support theme a while ago.. you can find it here: https://toolset.com/forums/topic/different-single-layout-templates-of-product-woocommerce-depending-on-category/

function assign_layout_by_post_status( $id, $layout ){
  if(!is_singular('/product')) return $id;  // add this line
        global $product;
				
		$product_cats = get_the_terms( $product->get_id(), 'product_cat');
		
		if(is_array($product_cats)){
				foreach($product_cats as $k=>$v):
					if($v->slug == 'rentalcarcat'){
						$id = 8670;
					}else if($v->slug == 'usedcarcat'){
						$id = 8674;
					}
				endforeach;
		}
			
        return $id;
}
 add_filter('get_layout_id_for_render', 'assign_layout_by_post_status', 10, 2);

Could you please let me know if this function is not working anymore? or do you have any alternative solution for this?

Thanks

#2439175

My issue is resolved now. Thank you!