Skip to content

Commit

Permalink
Only attempt to add empty attribute if page has attributes list
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsherman committed Jun 20, 2023
1 parent 97a9b02 commit d1e6c41
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions plugins/woocommerce/client/legacy/js/admin/meta-boxes-product.js
Expand Up @@ -435,29 +435,27 @@ jQuery( function ( $ ) {
} );
} );

// Attribute Tables.

// Initial order.
var woocommerce_attribute_items = $( '.product_attributes' )
.find( '.woocommerce_attribute' )
.get();

// If the product has no attributes, add an empty attribute to be filled out by the user.
$( function add_blank_custom_attribute_if_no_attributes() {
// Set up attributes, if current page has the attributes list.
const $product_attributes = $( '.product_attributes' );
if ( $product_attributes.length === 1 ) {
var woocommerce_attribute_items = $product_attributes.find( '.woocommerce_attribute' ).get();

// If the product has no attributes, add an empty attribute to be filled out by the user.
if ( woocommerce_attribute_items.length === 0 ) {
add_custom_attribute_to_list();
}
} );

woocommerce_attribute_items.sort( function ( a, b ) {
var compA = parseInt( $( a ).attr( 'rel' ), 10 );
var compB = parseInt( $( b ).attr( 'rel' ), 10 );
return compA < compB ? -1 : compA > compB ? 1 : 0;
} );
$( woocommerce_attribute_items ).each( function ( index, el ) {
$( '.product_attributes' ).append( el );
} );
// Sort the attributes by their position.
woocommerce_attribute_items.sort( function ( a, b ) {
var compA = parseInt( $( a ).attr( 'rel' ), 10 );
var compB = parseInt( $( b ).attr( 'rel' ), 10 );
return compA < compB ? -1 : compA > compB ? 1 : 0;
} );

$( woocommerce_attribute_items ).each( function ( index, el ) {
$product_attributes.append( el );
} );
}

function update_attribute_row_indexes() {
$( '.product_attributes .woocommerce_attribute' ).each( function (
Expand Down

0 comments on commit d1e6c41

Please sign in to comment.