Author Topic: Get customfield values progmatically  (Read 577 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 298
Get customfield values progmatically
« on: October 14, 2019, 17:44:58 pm »
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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10412
  • VirtueMart Version: 3+
Re: Get customfield values progmatically
« Reply #1 on: October 14, 2019, 21:30:42 pm »
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
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)