Merge pull request #32743 from helgatheviking/fix/32741-wc-category-search-return-ids

Optionally switch the category search selects to return category IDs
This commit is contained in:
Vedanshu Jain 2022-05-17 12:21:30 +05:30 committed by GitHub
commit 1d7bbdbc04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
Also allow getting category ID as option ID instead of term slug in wc-enhanced-select.

View File

@ -264,6 +264,8 @@ jQuery( function( $ ) {
// Ajax category search boxes
$( ':input.wc-category-search' ).filter( ':not(.enhanced)' ).each( function() {
var return_format = $( this ).data( 'return_id' ) ? 'id' : 'slug';
var select2_args = $.extend( {
allowClear : $( this ).data( 'allow_clear' ) ? true : false,
placeholder : $( this ).data( 'placeholder' ),
@ -287,7 +289,7 @@ jQuery( function( $ ) {
if ( data ) {
$.each( data, function( id, term ) {
terms.push({
id: term.slug,
id: 'id' === return_format ? term.term_id : term.slug,
text: term.formatted_name
});
});