Building E-commerce Sites with VirtueMart Cookbook
上QQ阅读APP看书,第一时间看更新

Custom fields – adding consistent global information to multiple products

Supposing there is a bit of information that is relevant to some or all of your products. Then consider that the information might change from time to time. Perhaps you have 100 products out of 150 that all come with a 30 day money back guarantee. You could enter that guarantee information into the product description. But what if you then change it to a 60 day guarantee? Even worse, what if some products changed to 60 days, some stayed the same, and some needed the guarantee removed?

Custom fields were designed for such nightmares. What we will do in this recipe is create a simple text custom field for 30 days money back guarantee.

Then you will be able to add or remove a custom field or edit the custom field using the information gained in this recipe and, as if by magic, all the products with that custom field will change too.

Getting ready

These simple text custom fields can be any text at all. Think about where you would need a consistent textual field in your store and read on to implement it.

How to do it...

First create the custom fields. Steps for creating the custom fields are as follows:

  1. Click on the Custom Fields tab from the Products menu on the left and click on the New button from the row of buttons near the top. You will see the following page:

    I admit it, this looks like a bit of an administrator's nightmare. But it is what gives VirtueMart a lot of its options and flexibility. With this one form you can create so many different features. That is why there are so many recipes on custom fields. Here is how to implement this one in 60 seconds or less:

  2. In the Custom Field Type: dropdown select String. String means text.
  3. In the Title field type, 30 day money back guarantee or whatever your standard text needs to say.
  4. Then in Default enter a description that relates to the title. This could be changed on a per product basis. Here QUALIFIES is entered for the guarantee.
  5. Last of all you can enter a helpful tool tip in the Tooltip field. This is a pop-up message when the title is hovered over by the customer's mouse. The following is an abbreviated and concatenated screenshot of the form to show you what is entered:
  6. Click on Save. Repeat for any other standard text you need to create.

Now let's add it to a product. Steps for adding the custom field to a product are as follows:

  1. Select the product you want to add the custom field to from the main products page. You can get there by selecting Products from the Products menu.
  2. Click on the Custom Fields tab, scroll to near the bottom, select the custom field you just made from the Custom field type dropdown. Click on Save and go and have a look at the text on your product in your store.

How it works...

You can now apply this custom field to any product that you like. It is true that future custom fields get a bit more complicated but a recipe at a time is a cinch.

There's more...

You could of course amend the text of your custom field, and all products assigned that custom field would also magically change.