Skip Navigation

[Resolved] Displaying Child Category For Woo Product

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
- 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 0 replies, has 1 voice.

Last updated by Timothy 1 day, 20 hours ago.

Assisted by: Minesh.

Author
Posts
#2806649

I am displaying a woocommerce product category with Legacy views. I am trying to show just the child category that is associated with this each product using a separate view that I inserted in the main view (the main view displays the product image/name,/description). But in the insreted view I see the message " This will filter out posts of the following types, because they are not hierarchical: Products" in the Post parent filter where I have selected " Parent is the current post in the loop" and in the loop of this view I have [wpv-post-taxonomy type="product_cat" format="name"]

You can see the current output at the bottom of this page:
hidden link

Tim

#2806691

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I do not see anything with the problem URL you shared. Maybe it requires login.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

Also, can you please tell me what views you created and where you added the view that displays child categories.

#2807220

Minesh
Supporter

Languages: English (English )

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

Can you please check now:

With the following view, I've passed the selected terms with view's shrotcode attribute "terms" as given under:
=> hidden link

 Category: [wpv-view name="show-sub-category-of-parent-category"  terms="[wpv-post-taxonomy type='product_cat' format='id' separator=',']" ]

Then with your view "show-sub-category-of-parent-category" - I've added the following query filter:
=> hidden link

Taxonomy term filter
Taxonomy term ID is set by the shortcode attribute "terms"

And at last - I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> hidden link

function func_display_subcats( $query_settings, $view_settings, $view_id  ){
 global $WP_Views;
  
    if ( $view_id == 897 ) {
     
     
      $child_terms = array();
      $selected_terms = $query_settings['include'];
      foreach($selected_terms as $k=>$v):
      	$current_term = get_term_by('id', $v , 'product_cat');
      	
      
      	if($current_term->parent!=0){
          	$child_terms[] = $current_term->term_id;
          
        }
      
      endforeach;
      
       $query_settings['include'] = $child_terms;
    }
    return $query_settings;
}
add_filter( 'wpv_filter_taxonomy_query', 'func_display_subcats', 99,3 );

Can you please confirm it works as expected.

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

#2807231

Excellent, this works.