Nutritional values
The Food and Supplements module in Polski for WooCommerce adds a nutrition facts table to each food product: energy in kJ and kcal, fat, saturates, carbohydrate, sugars, fibre, protein and salt, per 100 g or another reference you set. You enter the values on the product edit screen; the table appears on the product page and through the [polski_nutrients] shortcode. The module is off by default.
A food store must display a nutrition facts table (EU Regulation 1169/2011).
Supported nutrients
Section titled "Supported nutrients"According to Article 30 of the FIC Regulation, the nutrition facts table must contain at least energy, fat, saturates, carbohydrate, sugars, protein and salt. The plugin stores those plus fibre, nine values in total:
| Nutrient | Row label | Unit | JSON key |
|---|---|---|---|
| Energy value | Energy (kJ) | kJ | energy_kj |
| Energy value | Energy (kcal) | kcal | energy_kcal |
| Fat | Fat | g | fat |
| of which saturated fatty acids | of which saturates | g | saturated_fat |
| Carbohydrates | Carbohydrate | g | carbohydrates |
| of which sugars | of which sugars | g | sugars |
| Fibre | Fibre | g | fibre |
| Protein | Protein | g | protein |
| Salt | Salt | g | salt |
Other nutrients (vitamins, minerals, polyols, starch) have no field.
Configuration
Section titled "Configuration"Enabling the module
Section titled "Enabling the module"Go to Polski > Modules and enable Food and Supplements (module ID: food_module). Its settings are in Polski > Settings > Content & Trust, stored in the polski_food option.
Settings for the nutrition table
Section titled "Settings for the nutrition table"| Setting | Default | Description |
|---|---|---|
Show nutrients (show_nutrients) |
Yes | Shows or hides the table everywhere |
Caption prefix (nutrients_caption_prefix) |
Nutrition per | First part of the table caption |
Reference unit (nutrients_reference_unit) |
100 g | Second part of the caption, used when the product has no reference of its own |
Column name (nutrients_column_name) |
Nutrient | Header of the first column |
Column value (nutrients_column_value) |
Value | Header of the second column |
The same module also shows ingredients, allergens, Nutri-Score, alcohol content, country of origin, distributor and net content, each with its own on/off setting and label.
Entering data in the product editor
Section titled "Entering data in the product editor"Open the product, go to the Polski tab in the Product data box and find the Food and supplements group. It has one numeric field per nutrient and a Nutrition reference field.
- Leave a field empty to leave that row out of the table. Text that is not a number is ignored.
- Nutrition reference (
_polski_nutrient_reference_unit) says what the values are per, for example100 mlfor a drink. Empty uses the store default, normally100 g.
Storage format
Section titled "Storage format"The values are stored as JSON in the _polski_nutrients product meta, each with its value and unit:
{ "energy_kj": {"value": 1046, "unit": "kJ"}, "energy_kcal": {"value": 250, "unit": "kcal"}, "fat": {"value": 9.5, "unit": "g"}, "saturated_fat": {"value": 3.2, "unit": "g"}, "carbohydrates": {"value": 31, "unit": "g"}, "sugars": {"value": 5.4, "unit": "g"}, "protein": {"value": 8.7, "unit": "g"}, "salt": {"value": 1.2, "unit": "g"}}When reading, the plugin also accepts a plain number per key ("fat": 9.5), with the default unit. Unknown keys are ignored.
Shortcode
Section titled "Shortcode"[polski_nutrients] prints the table for the current product. Its only attribute is product:
[polski_nutrients][polski_nutrients product="123"]In a PHP template:
echo do_shortcode('[polski_nutrients product="' . $product->get_id() . '"]');The shortcode prints nothing when the module or the "Show nutrients" setting is off, or when the product has no values.
Where the table appears
Section titled "Where the table appears"On the single product page the table is part of the food information block, printed in the product summary (hook woocommerce_single_product_summary, priority 40). The block's template is single-product/food-info.php, which you can override in your theme.
Generated HTML table
Section titled "Generated HTML table"<div class="polski-nutrients"> <table class="polski-nutrients__table"> <caption>Nutrition per 100 g</caption> <thead><tr><th>Nutrient</th><th>Value</th></tr></thead> <tbody> <tr><td>Energy (kJ)</td><td>1046 kJ</td></tr> <tr><td>Energy (kcal)</td><td>250 kcal</td></tr> <tr><td>Fat</td><td>9.5 g</td></tr> <tr><td>of which saturates</td><td>3.2 g</td></tr> <!-- ... --> </tbody> </table></div>Rows follow the order of the table above. Numbers are printed as stored, with a dot as the decimal separator.
Programmatic access
Section titled "Programmatic access"Getting nutritional values
Section titled "Getting nutritional values"$product = wc_get_product($product_id);$nutrients = json_decode((string) $product->get_meta('_polski_nutrients'), true);
$energy_kcal = $nutrients['energy_kcal']['value'] ?? null;Saving nutritional values
Section titled "Saving nutritional values"Build the JSON with the plugin's helper, which takes the same key:value|key:value string as the CSV column:
use Polski\Service\FoodService;
$product = wc_get_product($product_id);$product->update_meta_data( '_polski_nutrients', FoodService::parseNutrientsCsv('energy_kj:1046|energy_kcal:250|fat:9.5|protein:8.7|salt:1.2'));$product->save();CSV import
Section titled "CSV import"The WooCommerce product CSV importer and exporter get a Nutrition values column (polski_nutrients). It uses pipe-separated key:value pairs:
"Fruit muesli","energy_kj:1590|energy_kcal:380|fat:8.2|saturated_fat:1.5|carbohydrates:64|sugars:22|fibre:7.5|protein:9.8|salt:0.05"Pairs with an unknown key or a value that is not a number are skipped.
CSS styling
Section titled "CSS styling".polski-nutrients__table { width: 100%; border-collapse: collapse;}
.polski-nutrients__table th,.polski-nutrients__table td { padding: 0.4em 0.8em; border-bottom: 1px solid #e0e0e0; text-align: left;}
.polski-nutrients__table caption { text-align: left; font-weight: 600;}Common issues
Section titled "Common issues"Nutrition facts table does not display
Section titled "Nutrition facts table does not display"- Check that the Food and Supplements module is enabled and "Show nutrients" is on
- Make sure at least one nutrient field on the product has a number
Values display with a dot instead of a comma
Section titled "Values display with a dot instead of a comma"The table prints the stored number as is, with a dot. The plugin does not apply locale number formatting to these values.
Which nutrients can I enter?
Section titled "Which nutrients can I enter?"Energy (kJ and kcal), fat, saturates, carbohydrate, sugars, fibre, protein and salt. There are no fields for vitamins or minerals.
Does the plugin calculate % reference intake?
Section titled "Does the plugin calculate % reference intake?"No. The table has two columns, nutrient and value.
How do I show values per 100 ml?
Section titled "How do I show values per 100 ml?"Type 100 ml in the product's Nutrition reference field. The caption then reads "Nutrition per 100 ml".