/** * Implements hook_preprocess_HOOK(). */ function green_deal_core_preprocess_commerce_product__teaser(&$variables) { $product = $variables['elements']['#commerce_product']; $product_variation = reset($product); $price = $product_variation->get('price')->number; $list_price = $product_variation->get('list_price')->number; if ($list_price != NULL) { $percentage = round((($list_price - $price) / $list_price) * 100); if ($percentage < 10) { $percentage = 10; } $variables['percentage'] = $percentage . '%'; } } function green_deal_core_preprocess_commerce_product__full(&$variables) { $product = $variables['elements']['#commerce_product']; $product_variation = reset($product); $price = $product_variation->get('price')->number; $list_price = $product_variation->get('list_price')->number; if ($list_price != NULL) { $percentage = round((($list_price - $price) / $list_price) * 100); if ($percentage < 10) { $percentage = 10; } $variables['percentage'] = $percentage . '%'; } }