SortOrder for Product Attributes Options Value in Magento2

 Create di.xml


<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\ConfigurableProduct\Model\AttributeOptionProvider"
type="Vendor\AttributeInOrder\Model\AttributeOptionProvider" />
</config>
__________

Create Model File
AttributeOptionProvider.php
<?php
declare(strict_types=1);

namespace Vendor\AttributeInOrder\Model;

use Magento\ConfigurableProduct\Model\AttributeOptionProvider as AttributeOptionModelProvider;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\Exception\LocalizedException;

class AttributeOptionProvider extends AttributeOptionModelProvider
{
/**
* Constructor
*
* @param Attribute $attributeResource
* @param ScopeResolverInterface $scopeResolver
* @param OptionSelectBuilderInterface $optionSelectBuilder
*/
public function __construct(
protected Attribute $attributeResource,
protected ScopeResolverInterface $scopeResolver,
protected OptionSelectBuilderInterface $optionSelectBuilder
) {
parent::__construct($attributeResource, $scopeResolver, $optionSelectBuilder);
}

/**
* Function for get attribute options
*
* @param AbstractAttribute $superAttribute
* @param int $productId
* @return array
* @throws LocalizedException
*/
public function getAttributeOptions(AbstractAttribute $superAttribute, $productId): array
{
$scope = $this->scopeResolver->getScope();
$select = $this->optionSelectBuilder->getSelect($superAttribute, (int)$productId, $scope);
$data = $this->attributeResource->getConnection()->fetchAll($select);
$sortByOptionTitle = false;

if ($superAttribute->getSourceModel()) {
$options = $superAttribute->getSource()->getAllOptions(false);

$optionLabels = [];
foreach ($options as $option) {
$optionLabels[$option['value']] = $option['label'];
}

foreach ($data as $key => $value) {
$optionText = $optionLabels[$value['value_index']] ?? false;

$data[$key]['default_title'] = $optionText;
$data[$key]['option_title'] = $optionText;

if (isset($data[$key]['attribute_code'])) {
//if ($data[$key]['attribute_code'] == 'color') {
$sortByOptionTitle = true;
//}
}
}
}
if ($sortByOptionTitle) {
if (preg_match('~[0-9]+~', $data[$key]['option_title'])) {
$keys = array_column($data, 'option_title');
array_multisort($keys, SORT_NUMERIC, $data);
} else {
usort($data, function ($key, $val) {
return strcmp(
$key['default_title'],
$val['default_title']
);
});
}
}
return $data;
}
}