Get the current ProductVariation from the formElement of a custom widget in the "Add to cart" form I've a custom field in my Order Item, i need the value of a field of my ProductVariation in the widget of my custom field.
Let's say that my Variation has a &quot;remote ID&quot; field, when i select one of the Variation in the Add to cart form, in my custom field i've to retrieve that ID and use it to do some things.
If i've only one Variation everything works great doing something like that:
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &amp;$form, FormStateInterface $form_state) {
    $purchased_entity = $items-&gt;getEntity()-&gt;getPurchasedEntity();
    
    $my_cusrom_id = $purchased_entity-&gt;get('my_variation_field')
      -&gt;first()
      -&gt;getValue()['value'];
  }

The only problem is that if I have multiple variations, when i chose one from the select, in this code always the first one is returned from the getPurchasedEntity method, and i see no informations in $form_state or $form of something that could be useful.
Is there a way to retrieve the selected variation from there? seems strange that's not possible...
At the moment i ended by getting the value directly from the $_POST, sounds a bit hacky but can't find another way to do that...