Body: <p>I am well-versed in CraftCMS and am finally able to use Craft Commerce 3 for the first time on a project (first time for any version of Commerce, actually) and it's to build a platform for a butcher shop to take orders for pick-up and delivery.</p>
  
  <p>One challenge is that this shop will have multiple types of quantity. For example, some products will be based on total pounds available (15 lbs. of ground beef), some on pre-created packages (more traditional item count), and others based on the length of cuts (i.e. 12" total available).</p>
  
  <p>I believe I will be able to use the default Quantity field for each of these scenarios and show the type of quantity on the front end with a simple radio field.</p>
  
  <p>Something I am now trying to figure out is the best way to handle products with options that could change the final product price.</p>
  
  <p>For example:
  <strong>Pork Shank</strong> - $8.00</p>
  
  <p>Options:</p>
  
  <ul>
  <li>Skin-on (+$0.00)</li>
  <li>Skin-off (+$1.00)</li>
  </ul>
  
  <p>In this example, the quantity is based on total pounds available, let's say 8.</p>
  
  <p>My first instinct was to use variants, but this won't work as each variant has its own quantity field and these products will each have only one main quantity field.</p>
  
  <p>I decided a good way to handle this might be a Matrix field that includes an option title and a table to enter the option label and associate cost increase.</p>
  
  <p><a href="https://i.sstatic.net/7rqJE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7rqJE.png" alt="Matrix example"></a></p>
  
  <p>This brings me to my main question: after ready through a variety of sources (many on Stack Exchange), it's clear that there is no way to manipulate the Commerce product/line-item price directly via the Twig templates. </p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/17515/per-item-ie-gift-wrapped-with-additional-cost-in-craft-commerce/17533#17533">This post</a> gave me the idea that creating a custom plugin to update the product line-item price is probably the way to go. Unfortunately, it seems that this was written in reference to an older version of Commerce.</p>
  
  <p>In addition, I am not confident in how I would actually trigger a custom plugin (assuming I would use the <a href="https://docs.craftcms.com/commerce/v3/events.html#populatelineitem" rel="nofollow noreferrer"><code>populateLineItem</code> event</a>, but also looking for guidance on this) via the Twig template.</p>
  
  <p>I would really appreciate any guidance on how I might create a custom plugin for this particular scenario, or if there is a better way to approach this than the one I am thinking of. Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-16T01:16:49.283Z
Comments.Text: did you find an answer to this? Just seems crazy there is no simple way to be able to add something to the base price when sending a line item to the cart if the user has selected an option. Anybody know the simplest way to be able to add manipulate the price of a product based on some simple options? Malcolm
Comments.UserDisplayName: Malcolm Maclean
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-19T10:46:01.233Z
Comments.Text: I would also be very interested in a solution for this. Using variants for that seems like overkill
Comments.UserDisplayName: Volker Andres
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-18T11:44:14.313Z
Comments.Text: To create a custom plugin I recommend using www.pluginfactory.io, you are correct about having to use populateLineItem event, you can find code example here (https://craftcms.com/docs/commerce/4.x/extend/events.html#populatelineitem).
Comments.UserDisplayName: Andrew Larsen
Tags: <ecommerce><plugin-craftcommerce3>
Title: Commerce 3 products with dynamic options
ThreadText: # Commerce 3 products with dynamic options
  
  (Asked by: username_0 on 2020-04-20)
  
  I am well-versed in CraftCMS and am finally able to use Craft Commerce 3 for the first time on a project (first time for any version of Commerce, actually) and it's to build a platform for a butcher shop to take orders for pick-up and delivery.
  
  One challenge is that this shop will have multiple types of quantity. For example, some products will be based on total pounds available (15 lbs. of ground beef), some on pre-created packages (more traditional item count), and others based on the length of cuts (i.e. 12" total available).
  
  I believe I will be able to use the default Quantity field for each of these scenarios and show the type of quantity on the front end with a simple radio field.
  
  Something I am now trying to figure out is the best way to handle products with options that could change the final product price.
  
  For example:
  **Pork Shank** - $8.00
  
  Options:
  
  * Skin-on (+$0.00)
  * Skin-off (+$1.00)
  
  In this example, the quantity is based on total pounds available, let's say 8.
  
  My first instinct was to use variants, but this won't work as each variant has its own quantity field and these products will each have only one main quantity field.
  
  I decided a good way to handle this might be a Matrix field that includes an option title and a table to enter the option label and associate cost increase.
  
  [![Matrix example](https://i.sstatic.net/7rqJE.png)](https://i.sstatic.net/7rqJE.png)
  
  This brings me to my main question: after ready through a variety of sources (many on Stack Exchange), it's clear that there is no way to manipulate the Commerce product/line-item price directly via the Twig templates.
  
  [This post](https://craftcms.stackexchange.com/questions/17515/per-item-ie-gift-wrapped-with-additional-cost-in-craft-commerce/17533#17533) gave me the idea that creating a custom plugin to update the product line-item price is probably the way to go. Unfortunately, it seems that this was written in reference to an older version of Commerce.
  
  In addition, I am not confident in how I would actually trigger a custom plugin (assuming I would use the [`populateLineItem` event](https://docs.craftcms.com/commerce/v3/events.html#populatelineitem), but also looking for guidance on this) via the Twig template.
  
  I would really appreciate any guidance on how I might create a custom plugin for this particular scenario, or if there is a better way to approach this than the one I am thinking of. Thanks!
  
  **Tags:** ecommerce, plugin-craftcommerce3
  
  > **Comments:**
  > **username_1**: did you find an answer to this? Just seems crazy there is no simple way to be able to add something to the base price when sending a line item to the cart if the user has selected an option. Anybody know the simplest way to be able to add manipulate the price of a product based on some simple options? username_1  
  > **username_2**: I would also be very interested in a solution for this. Using variants for that seems like overkill  
  > **username_3**: To create a custom plugin I recommend using www.pluginfactory.io, you are correct about having to use populateLineItem event, you can find code example here (https://craftcms.com/docs/commerce/4.x/extend/events.html#populatelineitem).  
  
  ---
  
  ## 0 answers
  
  