News:

Support the VirtueMart project and become a member

Main Menu

Get customfield values progmatically

Started by sandomatyas, October 14, 2019, 17:44:58 PM

Previous topic - Next topic

sandomatyas

What is the proper way to get the value of the custom fields of the product when I have only a virtuemart_product_id? getProduct() doesn't show it when it's a plugin type field. How should I fetch this data from VM API?

PRO

from where?


I USE

// gets a product param from single plugin
//$product , $param_name
function getParam($product,$param,$separated=''){
$return='';
   if   (!empty($product->customfieldsSorted['addtocart']))   {
     foreach ($product->customfieldsSorted['addtocart'] as $field) {
     if (!empty($field->$param)){
     $split='';
     if ($return!=''){$split=$separated;}
    $return.=$split.$field->$param;}

    }

    }
    return $return;
}


THEN.  ON PRODUCT PAGE
$labels=getParam($this->product,'PARAMETER-NAME',',');

IF on the category page or anywhere else, you would change

$this->product   to    $product