wc_change_get_terms_defaults( array $defaults, array $taxonomies )
Change get terms defaults for attributes to order by the sorting setting, or default to menu_order for sortable taxonomies.
Description Description
Parameters Parameters
- $defaults
-
(Required) An array of default get_terms() arguments.
- $taxonomies
-
(Required) An array of taxonomies.
Return Return
(array)
Source Source
File: includes/wc-term-functions.php
function wc_change_get_terms_defaults( $defaults, $taxonomies ) {
if ( is_array( $taxonomies ) && 1 < count( $taxonomies ) ) {
return $defaults;
}
$taxonomy = is_array( $taxonomies ) ? (string) current( $taxonomies ) : $taxonomies;
$orderby = 'name';
if ( taxonomy_is_product_attribute( $taxonomy ) ) {
$orderby = wc_attribute_orderby( $taxonomy );
} elseif ( in_array( $taxonomy, apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ), true ) ) {
$orderby = 'menu_order';
}
// Change defaults. Invalid values will be changed later @see wc_change_pre_get_terms.
// These are in place so we know if a specific order was requested.
switch ( $orderby ) {
case 'menu_order':
case 'name_num':
case 'parent':
$defaults['orderby'] = $orderby;
break;
}
return $defaults;
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |