Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
6 votes
Accepted

Display custom product field in cart

You could set a variable to access the products model like so: {% set product = item.purchasable.product %} and then access the fields like normal {{ product.myCustomField }} The snapshot holds the ...
Luke Pearce's user avatar
  • 3,863
6 votes
Accepted

How is Craft able to reuse fields in different Sections? (As opposed to EE.)

In Craft, all fields are stored in the craft_content table. They are otherwise independent of any field groups, layouts, sections, or anything else. PRO: This means that any element (Entry, Category, ...
Lindsey D's user avatar
  • 24k
4 votes
Accepted

How to pull out all user data in a template?

If i understand your question correct, you like to output the user data. I don't think that you need the getContent() function. But it's important, that you use the first() function. Here is your code:...
Tom Bauer's user avatar
  • 1,327
4 votes

Unable to store Model in Commerce Order Fields

When you assign element IDs to a relation field you need to pass the data in an array format. See this related answer: In a plugin, how do I save an entry with a related entry Key information in ...
Luke Holder's user avatar
  • 6,827
4 votes

How do I set the value of a custom entries order field from a plugin?

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field. Since an entries field is an array of elements, not just a single element, I just needed to ...
jthomas's user avatar
  • 373
4 votes
Accepted

date in database -1 day as on frond-end

The database will be storing the date as seconds since 1970 (epoch) and your view on that is not localised. However, the front end date is localised for your time zone. Of this I am more sure than ...
Jeremy Daalder's user avatar
4 votes

How to save a new entry with custom fields - Craft 3

It turns out the data wasn't being saved as I hadn't set a fieldLayoutId value. Now that I've figured this out, I've written a helper method to make saving any entry type much easier: public static ...
SteveEdson's user avatar
4 votes
Accepted

Adding Columns to a table

With the supercool table maker you can create dynamic tables. Is this what you are looking for?
Robin Schambach's user avatar
3 votes
Accepted

Add Checked Attribute to Custom User Fields on Frontend User Form

Solved! {% for letter in currentUser.newsletters.options %} <input type="checkbox" value="{{ letter.value }}" name="{{ letter.value }}" id="{{ letter.value }}" {% if letter.selected == ...
Chattervast's user avatar
3 votes

Option and notes fields after cart at checkout for order, not just line items

First, add a custom field to your orders, let's call it orderNotes. Then, in any updateCart form, you can use an input with name="fields[orderNotes]" to set the value of that field. (Line items ...
Jeremy Daalder's user avatar
3 votes
Accepted

More than one field for a fieldtype plugin

Nope – a single field can only have a single column in the craft_content table. If you need your FieldType to save complex data, you have two options: The easiest approach – by far – is to simply ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Checking value of customer order field within Plugin

What you're probably looking for is: if ($order->signupForNewsletter->contains('joinMailingList')) { echo "I've opted in"; } else { echo 'Not matched'; }
Brad Bell's user avatar
  • 67.5k
3 votes
Accepted

Custom Field on Settings page

You can’t change or add fields to the General Settings page, but for site wide available content Craft has this concept of Globals. See the documentation on it: https://craftcms.com/docs/globals It’...
carlcs's user avatar
  • 36.3k
3 votes

Get future multi-day event entries with custom date field

I think the simplest solution would be to make the eventEndDate field required even for single day events. Then you could do something like this: {% for event in craft.entries({ section:'events', ...
Alex Roper's user avatar
  • 2,632
3 votes

saving user field type custom field - Failed to set unsafe attribute

In order to set field values there is setFieldValue function $element->setFieldValue('fieldHandle', [Craft::$app->getUser()->getIdentity()->id]); All relation fields only accept the ...
Robin Schambach's user avatar
3 votes
Accepted

How to store custom data into a user

There are a whole bunch of ways to do what you want to do. You can add custom fields to user accounts. If you wanted to go with option 2 then you could create a custom text field and write the JSON ...
foamcow's user avatar
  • 2,019
3 votes
Accepted

Countries Field for Freeform

The answer: after you create a "select field", name it whatever you want - in this case country - and then add it to a form. Once you have done that, select that field within the form and ...
Roi Agneta's user avatar
  • 1,463
3 votes
Accepted

Get field settings of custom field via ElementInterface

I found the solution the values are stored in $this: public function normalizeValue($value, ElementInterface $element = null) { $type = $this->type; $shops = $this->shop; ... ...
antdev's user avatar
  • 137
3 votes
Accepted

Can I change a user field with twig without using a form?

Yes, it's possible via the special Twig do tag, which basically enables you to call methods without returning (i.e. outputting) anything (which is what happens with nearly every other Twig expression)....
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Add custom field value to Commerce Order Confirmation E-Mail

There are two ways of doing this: you can hook into the "live" product data using {{ item.purchasable.product.articleNumber }} -- and this is probably fine for the use-case of a confirmation ...
James Smith's user avatar
  • 5,284
2 votes
Accepted

Failed to add a custom field in settings

You're getting that error message because your PHP environment is displaying PHP Strict mode error messages. By default, Craft will explicitly disable those if devMode is enabled (error_reporting(...
Brad Bell's user avatar
  • 67.5k
2 votes
Accepted

Custom fields on a structure or section archive page

What you could do is make a "Global" Which sets the header image. You could name the global something like "Event Page Fields" or something like that so its clear for your administrator where to look. ...
Justin Dekkers's user avatar
2 votes
Accepted

Filter products by custom boolean field

Found the answer. When creating the where clauses for the query, there's a line that checks empty($str), so passing a false boolean value, PHP interprets it as an empty string, so the where clause ...
karinegomes's user avatar
2 votes
Accepted

Option and notes fields after cart at checkout for order, not just line items

You could create a special product for the gift wrapping and offer to add it to the cart during the checkout process with a separate updateCart form. As for the notes, you can add a custom field to ...
foamcow's user avatar
  • 2,019
2 votes

Retrieve entries on custom field date using ElementCriteriaModel

The Error was because $criteria->inspectionDate > '("now")'; This way you can't get today's date. You could try this: $date = new DateTime(); $formattedDate = $date->format(DateTime::...
hashtagerrors's user avatar
2 votes
Accepted

Retrieve entries on custom field date using ElementCriteriaModel

It seems like a syntax error, you did not set the date correctly. This should work $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'inspections'; ...
Robin Schambach's user avatar
2 votes

Adding Columns to a table

I used the method described here: "A User-Friendly Table Field" http://www.drivesimplicity.com/blog/a-user-friendly-table-field -- instruct the user to leave columns that he/she doesn't want blank and ...
userAW's user avatar
  • 176
2 votes
Accepted

Solspace Calendar: custom fields not outputting

This is a known issue and will be resolved in Beta 4 coming out today (March 15, 2018). Sorry for the trouble.
Solspace's user avatar
  • 1,410
2 votes

how to search for entries where a custom field is either not present or is empty

I've found that this is possible for lightswitch fields: craft.entries.myLightswitchField(':empty:') aka craft.entries({ myLightswitchField: ':empty:' }) returns all entries where the ...
henry's user avatar
  • 228
2 votes

How can additional custom fields be added to the Sites settings?

I would say the easiest thing is to create a set of Globals with all site specific settings. You can include custom settings for sites via Behaviors and Events and include your custom HTML and run ...
Robin Schambach's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible