Make sure attribute term dropdown adheres to sort order setting (#36047)

* Make sure attribute term dropdown adheres to sort order setting of attribute

* Fix spacing

* Fix lint errors
This commit is contained in:
louwie17 2022-12-21 04:11:12 -04:00 committed by GitHub
parent 679fac1bfa
commit 309ed6303f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix issue where attribute term dropdown was not adhering to sort order setting.

View File

@ -324,6 +324,7 @@ jQuery( function( $ ) {
return {
taxonomy: $( this ).data( 'taxonomy' ),
limit: $( this ).data( 'limit' ),
orderby: $( this ).data( 'orderby'),
term: params.term,
action: 'woocommerce_json_search_taxonomy_terms',
security: wc_enhanced_select_params.search_taxonomy_terms_nonce

View File

@ -37,13 +37,17 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( 'select' === $attribute_taxonomy->attribute_type ) {
$attribute_orderby = ! empty( $attribute_taxonomy->attribute_orderby ) ? $attribute_taxonomy->attribute_orderby : 'name';
?>
<select multiple="multiple" data-minimum_input_length="0" data-limit="50" data-return_id="id" data-placeholder="<?php esc_attr_e( 'Select terms', 'woocommerce' ); ?>" class="multiselect attribute_values wc-taxonomy-term-search" name="attribute_values[<?php echo esc_attr( $i ); ?>][]" data-taxonomy="<?php echo esc_attr( $attribute->get_taxonomy() ); ?>">
<select multiple="multiple"
data-minimum_input_length="0"
data-limit="50" data-return_id="id"
data-placeholder="<?php esc_attr_e( 'Select terms', 'woocommerce' ); ?>"
data-orderby="<?php echo esc_attr( $attribute_orderby ); ?>"
class="multiselect attribute_values wc-taxonomy-term-search"
name="attribute_values[<?php echo esc_attr( $i ); ?>][]"
data-taxonomy="<?php echo esc_attr( $attribute->get_taxonomy() ); ?>">
<?php
$args = array(
'orderby' => ! empty( $attribute_taxonomy->attribute_orderby ) ? $attribute_taxonomy->attribute_orderby : 'name',
'hide_empty' => 0,
);
$selected_terms = $attribute->get_terms();
if ( $selected_terms ) {
foreach ( $selected_terms as $selected_term ) {

View File

@ -1745,10 +1745,11 @@ class WC_AJAX {
$search_text = isset( $_GET['term'] ) ? wc_clean( wp_unslash( $_GET['term'] ) ) : '';
$limit = isset( $_GET['limit'] ) ? absint( wp_unslash( $_GET['limit'] ) ) : null;
$taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( wp_unslash( $_GET['taxonomy'] ) ) : '';
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : 'name';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => 'id',
'orderby' => $orderby,
'order' => 'ASC',
'hide_empty' => false,
'fields' => 'all',