[2.6] Variations script errors when 'empty' option is omitted (#11944)
* fix variation script malfunctioning when show_option_none arg is set to false * add minified version
This commit is contained in:
parent
50544233f5
commit
75b3042d9c
|
@ -332,18 +332,20 @@
|
|||
// Loop through selects and disable/enable options based on selections
|
||||
$form.find( '.variations select' ).each( function( index, el ) {
|
||||
|
||||
var current_attr_name, current_attr_select = $( el );
|
||||
var current_attr_name, current_attr_select = $( el ),
|
||||
show_option_none = $( el ).data( 'show_option_none' ),
|
||||
option_gt_filter = 'no' === show_option_none ? '' : ':gt(0)';
|
||||
|
||||
// Reset options
|
||||
if ( ! current_attr_select.data( 'attribute_options' ) ) {
|
||||
current_attr_select.data( 'attribute_options', current_attr_select.find( 'option:gt(0)' ).get() );
|
||||
current_attr_select.data( 'attribute_options', current_attr_select.find( 'option' + option_gt_filter ).get() );
|
||||
}
|
||||
|
||||
current_attr_select.find( 'option:gt(0)' ).remove();
|
||||
current_attr_select.find( 'option' + option_gt_filter ).remove();
|
||||
current_attr_select.append( current_attr_select.data( 'attribute_options' ) );
|
||||
current_attr_select.find( 'option:gt(0)' ).removeClass( 'attached' );
|
||||
current_attr_select.find( 'option:gt(0)' ).removeClass( 'enabled' );
|
||||
current_attr_select.find( 'option:gt(0)' ).removeAttr( 'disabled' );
|
||||
current_attr_select.find( 'option' + option_gt_filter ).removeClass( 'attached' );
|
||||
current_attr_select.find( 'option' + option_gt_filter ).removeClass( 'enabled' );
|
||||
current_attr_select.find( 'option' + option_gt_filter ).removeAttr( 'disabled' );
|
||||
|
||||
// Get name from data-attribute_name, or from input name if it doesn't exist
|
||||
if ( typeof( current_attr_select.data( 'attribute_name' ) ) !== 'undefined' ) {
|
||||
|
@ -385,7 +387,7 @@
|
|||
|
||||
} else {
|
||||
|
||||
current_attr_select.find( 'option:gt(0)' ).addClass( 'attached ' + variation_active );
|
||||
current_attr_select.find( 'option' + option_gt_filter ).addClass( 'attached ' + variation_active );
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -395,10 +397,10 @@
|
|||
}
|
||||
|
||||
// Detach unattached
|
||||
current_attr_select.find( 'option:gt(0):not(.attached)' ).remove();
|
||||
current_attr_select.find( 'option' + option_gt_filter + ':not(.attached)' ).remove();
|
||||
|
||||
// Grey out disabled
|
||||
current_attr_select.find( 'option:gt(0):not(.enabled)' ).attr( 'disabled', 'disabled' );
|
||||
current_attr_select.find( 'option' + option_gt_filter + ':not(.enabled)' ).attr( 'disabled', 'disabled' );
|
||||
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2160,21 +2160,22 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
|
|||
'show_option_none' => __( 'Choose an option', 'woocommerce' ),
|
||||
) );
|
||||
|
||||
$options = $args['options'];
|
||||
$product = $args['product'];
|
||||
$attribute = $args['attribute'];
|
||||
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
|
||||
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
|
||||
$class = $args['class'];
|
||||
$options = $args['options'];
|
||||
$product = $args['product'];
|
||||
$attribute = $args['attribute'];
|
||||
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
|
||||
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
|
||||
$class = $args['class'];
|
||||
$show_option_none = $args['show_option_none'] ? true : false;
|
||||
|
||||
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
|
||||
$attributes = $product->get_variation_attributes();
|
||||
$options = $attributes[ $attribute ];
|
||||
}
|
||||
|
||||
$html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '">';
|
||||
$html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '"' . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
|
||||
|
||||
if ( $args['show_option_none'] ) {
|
||||
if ( $show_option_none ) {
|
||||
$html .= '<option value="">' . esc_html( $args['show_option_none'] ) . '</option>';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue