<p>Something like this should work:</p>

<pre class="lang-php prettyprint-override"><code>public function init()
{
    craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function(Event $event) {
        $purchasable = $event-&gt;params['purchasable'];

        $myDropdownFieldValue = $purchasable-&gt;getProduct()-&gt;getContent()-&gt;myDropdownField;
    });
}
</code></pre>

<p>Relevant event docs: <a href="https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem" rel="nofollow noreferrer">https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem</a></p>

CC BY-SA 3.0
2016-08-21T16:54:20.803Z
I've tried using that followed by:
    `if($myDropdownFieldValue == 'xxx'){
       $lineItem->price = 25;
      }`
But it seems to apply it to every variant, regardless of the option chosen.
Adam Ladrach
CC BY-SA 3.0
2016-11-18T00:09:39.810Z
If you add your full code we can probably help with that...
Jeremy Daalder
CC BY-SA 3.0
2016-08-19T18:47:21.023Z
2017-11-13T17:43:19.357Z
2017-11-13T17:43:19.357Z
Brad Bell
<p>I'm trying to access a custom variant dropdown field in a plugin inside the <code>commerce_lineItems.onPopulateLineItem</code> event. How would I access the value of the dropdown, in order to do a comparison on it?</p>

<p>Thanks!</p>

<plugin-development><plugin-craftcommerce>
Get value of variant field in plugin
# Get value of variant field in plugin

(Asked by: username_0 on 2016-08-19)

I'm trying to access a custom variant dropdown field in a plugin inside the `commerce_lineItems.onPopulateLineItem` event. How would I access the value of the dropdown, in order to do a comparison on it?

Thanks!

**Tags:** plugin-development, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-08-19. Score: 1

Something like this should work:
public function init()
{
    craft()->on('commerce_lineItems.onPopulateLineItem', function(Event $event) {
        $purchasable = $event->params['purchasable'];

        $myDropdownFieldValue = $purchasable->getProduct()->getContent()->myDropdownField;
    });
}

Relevant event docs: https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem

> **Comments:**
> **username_0**: I've tried using that followed by:     `if($myDropdownFieldValue == 'xxx'){        $lineItem->price = 25;       }` But it seems to apply it to every variant, regardless of the option chosen.  
> **username_2**: If you add your full code we can probably help with that...  

---

