Home Forums Basel support forum Variations issue with default form values are sold out scenario Reply To: Variations issue with default form values are sold out scenario

#131255

Artem Temos
Keymaster

Try to add the following code snippet to the Custom JS area in Theme Settings to fix this issue.

jQuery('.variations_form').each(function () {
	var $variation_form = jQuery(this);

	$variation_form.on('update_variation_values', function (e) {
		// Count available options.
		$variation_form.find('.variations select').each(function () {
			var $select = jQuery(this);
			var attached_options_count = $select.find('option.attached').length;
			var selected_attr_val = $select.val() || '';
			var selected_attr_val_valid = true;

			// Check if current selection is in attached options.
			if (selected_attr_val) {
				selected_attr_val_valid = false;

				if (0 !== attached_options_count) {
					$select.find('option.attached.enabled').each(function () {
						var option_value = jQuery(this).val();

						if (selected_attr_val === option_value) {
							selected_attr_val_valid = true;
							return false; // break.
						}
					});
				}
			}

			// Choose selected value.
			if (selected_attr_val) {
				// If the previously selected value is no longer available, fall back to the placeholder (it's going to be there).
				if (!selected_attr_val_valid) {
					$variation_form.find('.basel-swatch[data-value=' + selected_attr_val + ']').removeClass('active-swatch');
				}
			}

		});
	});
});

Also, remove the code you have there since it is broken and may cause problems with the fix http://prntscr.com/oaelov