PDF template condition


I do have a pdf template that is related to invoices, and i want that if some product prize is 0$, this prize doesn’t appear, so only appears the name of the product with no prize because it’s zero.
How can I do that, maybe with some javascript in the html template?


Some help please!

You would need to modify the code which generates the pdf. templateParser.php - Make sure to do you work in the custom folder to make it upgrade safe.

1 Like

I’m sorry to ask again, but in the templateParser.php file, where should i put the code “if (number==0){//Dont print anything}”? I’m not familiar with php.


In the foreach ($repl_arr as $name => $value) {

Something like(obviously replace field name):
if ($name === ‘field_name’ && $value == 0) { $value = “”; }

Hey thanks, I tried this, but it didn’t work:
Those fields are from line items.

if ($name === 'service_product_total_price' && $value == 0) 
				$value = ""; 
			if ($name === 'service_product_list_price' && $value == 0) 
				$value = ""; 
			if ($name === 'service_vat_amt' && $value == 0) 
				$value = ""; 

It is something I did wrong?

Thanks again!

Field names are probably wrong, drop a breakpoint in a debugger to find the correct values for the name and value. total price would probably be in this format too:
if ($name === ‘field_name’ && $value == “0.00”) { $value = “”; }

I’m really stuck on this, the fields that i want to “remove” from the pdf, are, in the line items, the vats(service_vat_amt), total price(service_product_total_price) and price(service_product_list_price), I think these are the names of the variables, but It’s not working :frowning:

This works for list price:

            if($name == "aos_products_quotes_product_list_price" && $value == "0.00"){
                $value = "";

Hey thanks, another question, does it matter where i put the code(at the end of the code, start, etc.)? I mean inside the foreach ($repl_arr as $name => $value).

It has to be before:

if ($value != '' && is_string($value)) {
$string = str_replace("\$$name", $value, $string);

Ok, so you said that

if($name == "aos_products_quotes_product_list_price" && $value == "0.00"){
                $value = "";

works fine, in my case, i want the service line, so it would be something like this?

It’s working!!

Thanks so much for your help <3

Have you figured out the field name for service total price?

aos_products_quotes_product_list_price is working but I couldn’t get aos_services_quotes_service_total_price work