Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-21T16:54:20.803Z
Answers.Text: 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.
Answers.UserDisplayName: Adam Ladrach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-18T00:09:39.810Z
Answers.Text: If you add your full code we can probably help with that...
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T18:47:21.023Z
Answers.LastActivityDate: 2017-11-13T17:43:19.357Z
Answers.LastEditDate: 2017-11-13T17:43:19.357Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugin-development><plugin-craftcommerce>
Title: Get value of variant field in plugin
ThreadText: # 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:
  
  ```php
  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...  
  
  ---
  
  