Advertisement
Fany_VanDaal

Seřazení produktů dle zařazení subkategorií

Apr 26th, 2020
334
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // seřazení produktů dle zařazení subkategorií
  2. function woocommerce_get_product_category_of_subcategories( $category_slug ){
  3.   $terms_html = array();
  4.   $taxonomy = 'product_cat';
  5.   $parent = get_term_by( 'slug', $category_slug, $taxonomy );
  6.   $children_ids = get_term_children( $parent->term_id, $taxonomy );
  7.   foreach($children_ids as $children_id){
  8.         $term = get_term( $children_id, $taxonomy );
  9.         $term_link = get_term_link( $term, $taxonomy );
  10.         if ( is_wp_error( $term_link ) ) $term_link = '';
  11.         $terms_html[] = '<a href="' . esc_url( $term_link ) . '" rel="tag" class="' . $term->slug . '">' . $term->name . '</a>';
  12.   }
  13.   return '<span class="subcategories-' . $category_slug . '">' . implode( ', ', $terms_html ) . '</span>';
  14. }
Advertisement
RAW Paste Data Copied
Advertisement