wc_reorder_terms()
Move a term before the a given element of its hierarchy level.
Хуки из функции
Возвращает
int
.
Использование
wc_reorder_terms( $the_term, $next_id, $taxonomy, $index, $terms );
- $the_term(int) (обязательный)
- Term ID.
- $next_id(int) (обязательный)
- The id of the next sibling element in save hierarchy level.
- $taxonomy(строка) (обязательный)
- Taxonomy.
- $index(int)
- Term index .
По умолчанию: 0) - $terms(разное)
- List of terms. .
По умолчанию: null)
Код wc_reorder_terms() wc reorder terms WC 9.4.2
function wc_reorder_terms( $the_term, $next_id, $taxonomy, $index = 0, $terms = null ) { if ( ! $terms ) { $terms = get_terms( $taxonomy, 'hide_empty=0&parent=0&menu_order=ASC' ); } if ( empty( $terms ) ) { return $index; } $id = intval( $the_term->term_id ); $term_in_level = false; // Flag: is our term to order in this level of terms. foreach ( $terms as $term ) { $term_id = intval( $term->term_id ); if ( $term_id === $id ) { // Our term to order, we skip. $term_in_level = true; continue; // Our term to order, we skip. } // the nextid of our term to order, lets move our term here. if ( null !== $next_id && $term_id === $next_id ) { $index++; $index = wc_set_term_order( $id, $index, $taxonomy, true ); } // Set order. $index++; $index = wc_set_term_order( $term_id, $index, $taxonomy ); /** * After a term has had it's order set. */ do_action( 'woocommerce_after_set_term_order', $term, $index, $taxonomy ); // If that term has children we walk through them. $children = get_terms( $taxonomy, "parent={$term_id}&hide_empty=0&menu_order=ASC" ); if ( ! empty( $children ) ) { $index = wc_reorder_terms( $the_term, $next_id, $taxonomy, $index, $children ); } } // No nextid meaning our term is in last position. if ( $term_in_level && null === $next_id ) { $index = wc_set_term_order( $id, $index + 1, $taxonomy, true ); } return $index; }