Price Modifiers

See also: price modifiers fieldtype

A key feature of CartThrob is the ability to create customer selectable options. Examples include: t-shirt sizes, color options, customer personalization and messages, engraving, and computer memory upgrades. These selectable options may affect price, or may just require continued storage after purchase.

There are three parts to creating options for your products: 1. channel configuration 2. outputting those options into the template, and 3. getting the configured data into your purchased items and orders channel.

Below is a straightforward description of how to complete each of these steps. There's a lot of flexibility in how you put this together, which in some regards makes it the most complex aspect of CartThrob. Since every cart with customer selectable options needs to work a bit differently, CartThrob doesn't expect the data in one single format.

Before you begin creating your product options, make sure you have quizzed your client in detail. We often find that the clients themselves have difficulty explaining or even understanding their own business rules for customer selectable options. Unfortunately, you may have to hold their hands through this process to gather a good understanding of how your client's store should work.

It's common to create a base price for a product, and then set price modifiers to raise or lower that price. You may also avoid setting a base price and use the modifiers themselves to set the whole price of the product.

Using channels to Manage Price Modifiers

Adding a CartThrob Price Modifier Custom Field

There's a custom channel field for price modifiers that can be used in a channel entry. You can also use Brandon Kelly's Matrix field, (an example of which is located a bit further on). To get started, create a new custom channel field for your price modifier.


Once this field is created you can begin adding options to your channel.


Using Matrix as a Price Modifier Field Instead

Using Matrix for your price modifier is pretty easy. You just need a few required matrix fields called "option_value", and "price", and optionally "option_name". You can put these fields in any order you like and add as many additional fields as you want. The only requirement is that you have fields with short names of "option_value" and "price".


What's Going on Under the Hood When Using Price Modifiers

Price modifiers are made up of the channel field and the template tags. The channel field helps you get structured data into your system. The template tags get that data out, and facilitate the addition of data back into the system for use in an Orders channel and Purchased Items channel.

The real magic comes from the code used in the template… the code that lets a customer select an option. CartThrob can automatically figure out and compute the price based on the customer's selection when using the add_to_cart_form tag. You don't need to output the price anywhere in your template, CartThrob will figure it out. You can output the price, but you don't have to.

Templates are discussed in more detail below, but it's important to note the power of the add_to_cart_form's item_options variable. Not only can you use it to output your price modifiers, it can also be used to create fields that allow the addition of dynamic content (text, licenses, notes, love poems, etc.) to a product. This item_options variable makes it possible to store additional customer data in the Orders and Purchased Items channels. This tag facilitates both the output of your product options, and custom input. It's a bit difficult to understand at first, but at some point understanding this variable will spark the ‘a-ha' moment… you'll start to figure out that the possibilities are almost endless.