Hi, thanks in advance for anyone who can help.
I am trying to update a VM template, I need to call a single Virtuemart Custom Field in this example Theme. I only need to be a able to call this single customfield into the template not the whole array I only really need the variable. I am completely stumped. :'(
What I am trying to achieve is to use the value of the custom field string in the PHP code to call up different artwork for the page type e.g. a custom field String: "Theme"which has a value of "Jungle" and then echo the variable "jungle" into my code.
VirtueMart 3.0.16
Regards
Steve Jackson
<?php
$value='';
if (!empty($product->customfieldsSorted['my-position'])) {
foreach ($product->customfieldsSorted['my-position'] as $field) {
$value =$field->customfield_value;
} }
if ($value=='Jungle'){
your code goes here
}
?>
if its not $field->customfield_value
then it is $field->customfield_params
Hi Pro
Thanks for your reply, but it doesn't seem to be working. Nothing is display, I have put my custom string in a position of my-position. I have tried both variations of $field->customfield_value and $field->customfield_params.
<?php
$producttheme='';
if (!empty($product->customfieldsSorted['my-position'])) {
foreach ($product->customfieldsSorted['my-position'] as $field) {
$value =$field->customfield_params;
} }
if ($producttheme=='jungle'){
echo "Hello world!";
}
echo $producttheme ;
?>
you did not change
$value =$field->customfield_params;
Hi Pro
I have changed that it has made no difference. I have tried both of the below:
<?php
$producttheme='';
if (!empty($product->customfieldsSorted['my-position'])) {
foreach ($product->customfieldsSorted['my-position'] as $field) {
$producttheme =$field->customfield_value;
} }
if ($producttheme=='jungle'){
echo "Hello world!";
}
echo $producttheme ;
?>
<?php
$value='';
if (!empty($product->customfieldsSorted['my-position'])) {
foreach ($product->customfieldsSorted['my-position'] as $field) {
$value =$field->customfield_value;
} }
if ($value=='Jungle'){
echo "your code goes here";
}
?>
If I set the variable manually it works $producttheme='jungle';
Please forgive my ignorance, my PHP is rusty.
Regards
Steve
what happens when you echo this
echo $producttheme ;
what shows up?
Good Morning Pro
I have tried echo $producttheme; and echo $value ; respectively outputs nothing, it is like the if statement is not referencing the customfields correctly, am I supposed to do anything with the custom field string other than assign it a layout location e.g. in the template etc?
I have attached a screenshot of the custom string properties. The custom field is a string, Title is "Theme" Layout position is "my-position" it is set to show title and is published and works the custom field displays if I leave the layout blank and is called with the other custom fields using the following code:
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'normal'));
I have also tried changing $product->customfieldsSorted['my-position'] to $product->customfields['my-position']
I have also used a echo '<pre>',print_r($producttheme,1),'</pre>'; function to see if any variable is being held and it just comes up blank.
I have tried it on both a converted VM2 and the standard VM templates.
Regards
Steve
Do you see anything with this code:
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'my-position'));
?
And where are you adding the codes? To product details layout default.php?
Yes that works, that shows the custom string of Theme Jungle
Yes this is the location I am adding it to
That works but I still need to get the value outputted as a variable so I can use it.
Quote from: PRO on May 31, 2016, 17:20:50 PM
<?php
$value='';
if (!empty($product->customfieldsSorted['my-position'])) {
foreach ($product->customfieldsSorted['my-position'] as $field) {
$value =$field->customfield_value;
} }
if ($value=='Jungle'){
your code goes here
}
?>
if its not $field->customfield_value
then it is $field->customfield_params
^^^
Change $product to $this->product.
http://forum.virtuemart.net/index.php?topic=100696.0
Thanks so much Ghost, that has worked. ;D
For reference to anyone else looking this is my final code:
$producttheme='';
if (!empty($this->product->customfieldsSorted['my-position'])) {
foreach ($this->product->customfieldsSorted['my-position'] as $field) {
$producttheme =$field->customfield_value;
} };