Do not disable "Used for variations" checkbox (#39502)

This commit is contained in:
Matt Sherman 2023-08-01 10:01:42 -04:00 committed by GitHub
commit 85e37739d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 40 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Do not disable "Used for variations" checkbox on attribute.

View File

@ -126,34 +126,6 @@ jQuery( function ( $ ) {
return false;
} );
function disable_or_enable_fields() {
var product_type = $( 'select#product-type' ).val();
$( `.enable_if_simple` ).each( function () {
$( this ).addClass( 'disabled' );
if ( $( this ).is( 'input' ) ) {
$( this ).prop( 'disabled', true );
}
} );
$( `.enable_if_external` ).each( function () {
$( this ).addClass( 'disabled' );
if ( $( this ).is( 'input' ) ) {
$( this ).prop( 'disabled', true );
}
} );
$( `.enable_if_variable` ).each( function () {
$( this ).addClass( 'disabled' );
if ( $( this ).is( 'input' ) ) {
$( this ).prop( 'disabled', true );
}
} );
$( `.enable_if_${ product_type }` ).each( function () {
$( this ).removeClass( 'disabled' );
if ( $( this ).is( 'input' ) ) {
$( this ).prop( 'disabled', false );
}
} );
}
// Product type specific options.
$( 'select#product-type' )
.on( 'change', function () {
@ -173,7 +145,6 @@ jQuery( function ( $ ) {
}
show_and_hide_panels();
disable_or_enable_fields();
change_product_type_tip( get_product_tip_content( select_val ) );
$( 'ul.wc-tabs li:visible' ).eq( 0 ).find( 'a' ).trigger( 'click' );
@ -436,12 +407,19 @@ jQuery( function ( $ ) {
// 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();
// When the attributes tab is shown, add an empty attribute to be filled out by the user.
$( '#product_attributes' ).on( 'woocommerce_tab_shown', function() {
remove_blank_custom_attribute_if_no_other_attributes();
// 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();
}
const 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();
}
} );
const woocommerce_attribute_items = $product_attributes.find( '.woocommerce_attribute' ).get();
// Sort the attributes by their position.
woocommerce_attribute_items.sort( function ( a, b ) {
@ -500,6 +478,7 @@ jQuery( function ( $ ) {
url: woocommerce_admin_meta_boxes.ajax_url,
data: {
action: 'woocommerce_add_attribute',
product_type: $( '#product-type' ).val(),
taxonomy: globalAttributeId ? globalAttributeId : '',
i: indexInList,
security: woocommerce_admin_meta_boxes.add_attribute_nonce,
@ -568,7 +547,7 @@ jQuery( function ( $ ) {
toggle_expansion_of_attribute_list_item( $attributeListItem );
disable_or_enable_fields();
$( document.body ).trigger( 'woocommerce_added_attribute' );
jQuery.maybe_disable_save_button();
} catch ( error ) {
@ -914,8 +893,6 @@ jQuery( function ( $ ) {
// Hide the 'Used for variations' checkbox if not viewing a variable product
show_and_hide_panels();
disable_or_enable_fields();
// Make sure the dropdown is not disabled for empty value attributes.
$( 'select.attribute_taxonomy' )
.find( 'option' )

View File

@ -126,7 +126,9 @@ jQuery( function ( $ ) {
$( 'ul.wc-tabs li', panel_wrap ).removeClass( 'active' );
$( this ).parent().addClass( 'active' );
$( 'div.panel', panel_wrap ).hide();
$( $( this ).attr( 'href' ) ).show();
$( $( this ).attr( 'href' ) ).show( 0, function () {
$( this ).trigger( 'woocommerce_tab_shown' );
} );
} );
$( 'div.panel-wrap' ).each( function () {
$( this )

View File

@ -93,7 +93,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<tr>
<td>
<div class="enable_variation show_if_variable">
<label><input type="checkbox" disabled class="woocommerce_attribute_used_for_variations checkbox enable_if_variable" <?php checked( $attribute->get_variation(), true ); ?> name="attribute_variation[<?php echo esc_attr( $i ); ?>]" value="1" /> <?php esc_html_e( 'Used for variations', 'woocommerce' ); ?></label>
<label><input type="checkbox" class="woocommerce_attribute_used_for_variations checkbox" <?php checked( $attribute->get_variation(), true ); ?> name="attribute_variation[<?php echo esc_attr( $i ); ?>]" value="1" /> <?php esc_html_e( 'Used for variations', 'woocommerce' ); ?></label>
</div>
</td>
</tr>

View File

@ -611,6 +611,8 @@ class WC_AJAX {
wp_die( -1 );
}
$product_type = isset( $_POST['product_type'] ) ? sanitize_text_field( wp_unslash( $_POST['product_type'] ) ) : 'simple';
$i = absint( $_POST['i'] );
$metabox_class = array();
$attribute = new WC_Product_Attribute();
@ -619,7 +621,13 @@ class WC_AJAX {
$attribute->set_name( sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) ) );
/* phpcs:disable WooCommerce.Commenting.CommentHooks.MissingHookComment */
$attribute->set_visible( apply_filters( 'woocommerce_attribute_default_visibility', 1 ) );
$attribute->set_variation( apply_filters( 'woocommerce_attribute_default_is_variation', 1 ) );
$attribute->set_variation(
apply_filters(
'woocommerce_attribute_default_is_variation',
'variable' === $product_type ? 1 : 0,
$product_type
)
);
/* phpcs: enable */
if ( $attribute->is_taxonomy() ) {