TransWikia.com

Craft Commerce Product Options that increase price, but do NOT affect stock

Craft CMS Asked by GlennJ on November 23, 2020

My client wishes to sell artwork online. They’re all one-off pieces and once one is sold, it should not be available to purchase thereafter.

However, the artwork needs to have an option to be framed which would increase the price.

I can’t see how this can be achieved with Variants as each variant has their own stock level.

One Answer

Worked it out!

Putting this in a custom module should do the trick..., obviously changing the price modifier and option name to your needs.

        Event::on(
            LineItems::class,
            LineItems::EVENT_POPULATE_LINE_ITEM,
            function(LineItemEvent $event) {
                // @var LineItem $lineItem
                $lineItem = $event->lineItem;
                // @var bool $isNew
                $isNew = $event->isNew;

                if (isset($lineItem->options['giftWrapped']) && $lineItem->options['giftWrapped'] == 'yes') {
                    $lineItem->price += 20;
                }
            }
        );

Correct answer by GlennJ on November 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP