Добавить сворачивание для подменю в раскрывающемся списке wordpress

#php #wordpress #bootstrap-4

Вопрос:

Я использую плагин WCFM, в котором есть фильтр для отображения поставщиков на основе категорий, в настоящее время подкатегории имеют —— подпись перед заголовком, я хочу добавить сворачивание для категорий. Пример: когда пользователь нажимает на название категории, пользователю должны отображаться свернутые подкатегории, и пользователь может выбрать подкатегорию.

На данный момент у меня более 50 подкатегорий для каждых 10 категорий, что делает список очень длинным, свернуть решит проблему.

Код:

 lt;?php if( $category amp;amp; apply_filters( 'wcfmmp_is_allow_store_list_category_filter', true ) ) { ?gt;  lt;?php  $vendor_categories = $WCFMmp-gt;wcfmmp_vendor-gt;wcfmmp_get_vendor_taxonomy( 0, 'product_cat' );  if ( $vendor_categories ) {  $preferred_taxonomy = 'product_cat';  ?gt;  lt;select id="wcfmmp_store_category" name="wcfmmp_store_category" class="wcfm-select wcfm_ele"gt;  lt;option value=""gt;lt;?php _e( 'Choose Category', 'wc-multivendor-marketplace' ); ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_categories as $vendor_category_id =gt; $vendor_category ) {  if( $vendor_category_id ) {  if( !apply_filters( 'wcfm_is_allow_store_list_taxomony_by_id', true, $vendor_category_id, $preferred_taxonomy ) ) continue;  if( is_array( $vendor_category ) amp;amp; !empty( $vendor_category ) ) {  $vendor_term = get_term( absint( $vendor_category_id ), $preferred_taxonomy );   $tax_toggle_class = '';  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  foreach( $vendor_category as $vendor_category_child_id =gt; $vendor_category_child ) {  $vendor_term = get_term( absint( $vendor_category_child_id ), $preferred_taxonomy );  if( !is_array( $vendor_category_child ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;—lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;—lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child as $vendor_category_child2_id =gt; $vendor_category_child2 ) {  $vendor_term = get_term( absint( $vendor_category_child2_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child2 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;——lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;——lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child2 as $vendor_category_child3_id =gt; $vendor_category_child3 ) {  $vendor_term = get_term( absint( $vendor_category_child3_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child3 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;———lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;———lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child3 as $vendor_category_child4_id =gt; $vendor_category_child4 ) {  $vendor_term = get_term( absint( $vendor_category_child4_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child4 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child4 as $vendor_category_child5_id =gt; $vendor_category_child5 ) {  $vendor_term = get_term( absint( $vendor_category_child5_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child5 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;—————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;—————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child5 as $vendor_category_child6_id =gt; $vendor_category_child6 ) {  $vendor_term = get_term( absint( $vendor_category_child6_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child6 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;——————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;——————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  foreach( $vendor_category_child6 as $vendor_category_child7_id =gt; $vendor_category_child7 ) {  $vendor_term = get_term( absint( $vendor_category_child7_id ), $preferred_taxonomy );   if( !is_array( $vendor_category_child7 ) ) {  if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;———————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  } else {  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;———————lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php  }  }  }  }  }  }  }  }  }  }  }  }  }  }  } else {  $vendor_term = get_term( absint( $vendor_category_id ), $preferred_taxonomy );   if( $vendor_term amp;amp; $vendor_term-gt;term_id amp;amp; $vendor_term-gt;name ) {  if( in_array( $vendor_term-gt;term_id, $display_vendor_term) ) continue;  $display_vendor_term[$vendor_term-gt;term_id] = $vendor_term-gt;term_id;  ?gt;  lt;option value="lt;?php echo $vendor_term-gt;term_id; ?gt;" lt;?php if( $vendor_term-gt;term_id == $search_category ) echo 'selected'; ?gt;gt;lt;?php echo $vendor_term-gt;name; ?gt;lt;/optiongt;  lt;?php   }  }  }   }  ?gt;  lt;/selectgt;  lt;?php } ?gt;  lt;?php do_action( 'wcfmmp_after_store_list_category_filter', $args ); ?gt;  lt;?php } ?gt;