When making a new Custom Field, there is a box asking for its Layout position:
Custom Fields>Custom Field>Layout position
I learned from a YouTube video that this (for my case) had to be set to <addtocart> (no spaces)
Usually in Joomla, 'Layout position' fields offer a drop-down menu to select from a list of available possibilities. My forum account here does not permit me to post to the 'Requested Features' board, but:
(i) Why is there no drop-down menu here?
(ii) Where can one find the list of available 'Layout position' options for VM3, showing the correct format of wording (e.g. <addtocart>) to type into the Layout position box?
Many thanks in advance guys!
The position required by the vast majority of custom field users will be 'addtocart' - ie the custom field is within the add to cart form so the value is available there to be shown when that product is added to cart.
In the file components/com_virtuemart/views/category/tmpl/default.php you can see alternative positions added by default, such as 'ontop' which is just above the vm-product-container div, or 'normal' just after the product full description. There is also 'onbot' and postions for 'related-products'. The first three are rarely used, but the developer can add additional field positions should they be required in different positions simply by adding a code snippet to the default.php and using that file as a template override. eg: to add 'mynewposition'
<?php
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'mynewposition'));
?>
I suppose a selector could be used to display the positions but it would require addtocart to be the default and would rarely be used.
Thank you jenkinhill, this solves things! ;D
ontop | - Just above the VM product container <div> |
normal | - Just after the product full description |
onbot | - Just below the VM product container <div> |
addtocart | - Within the 'Add to cart' form |
hi, can a custom field have two different positions (is this even possible with defining two separate CSS classes?
1) in category layout
2) product details page?
thanks in advance
You can display a customfield at two different positions. But this needs some extra code in your category and productdetail template.
Jörgen @ Kreativ Fotografi
Hi mate, thanks for the reply, i am using latest version of joomla and virtuemart.
Joomla! 3.9.5
VirtueMart 3.4.2
what files exactly do i need to change and can you shed some light on it please? thanks
A customfield position is rendered in product with code
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'ontop'));
This render the customfiled in position 'ontop' using sublayouts/customfields.php
The defualt file isf YOURJOOMLA/components/com_virtuemart/sublayouts/customfields.php
and template override
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/customfields.php
If you want anohter render you can use for eg.
echo shopFunctionsF::renderVmSubLayout('mycustomfieldrender',array('product'=>$this->product,'position'=>'ontop'));
and add a copy of default in the template
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/mycustomfieldrender.php
and modify the code in this file
If the custom field is not in the addtocart position, its price does not affect the product price, how can this problem be solved?
The customfield need to be in the HTML form to be calculated
If you need this then modify your HTML