Page 1 of 1

Hide price if 0

Posted: Fri Jul 26, 2019 8:19 am
by MeckerOpa
Hello guys, I used a mod that would hide my prices when they are zero, in version 2.x. . But this mod isn't working in version 3.x.

I need some help how I can hide the prices if they are zero. Maybe someone knows a mod for that. I would be really thankful! It's very important for me, that the price won't show if it is 0. Because the price will be calculated by a formula.

Re: Hide price if 0

Posted: Fri Jul 26, 2019 4:02 pm
by letxobnav
easiest way is to alter the currency format function:
system/library/cart/currency.php

Code: Select all

public function format($number, $currency, $value = '', $format = true) {
add:

Code: Select all

if ($number == 0) return false;


more work intensive way is to change wherever the price is fetched and change it to false instead of formatting it with currency for example:

in catalog/controller/product/category.php

change:

Code: Select all

			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
			} else {
				$price = false;
			}
into:

Code: Select all

			$price = false;
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				if ($result['price']) > 0) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				}
			}

in catalog/controller/product/product.php

change:

Code: Select all

			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
			} else {
				$data['price'] = false;
			}
into:

Code: Select all

			$data['price'] = false;
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				if ($product_info['price']) > 0) {
					$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				}
			}

and there are more places to do this.

Re: Hide price if 0

Posted: Sat Jul 27, 2019 2:45 am
by MeckerOpa
Holy cow... :crazy: :choke: Okay... I thought this would be peanuts... Okay I already bought an extension, that gives me the opportunity to hide the price for selected products. This was really a lot of work, but it works.

Thanks for your help but my knowledge isn't that good, so I would not try to replace code in the template.

The extension: https://www.opencart.com/index.php?rout ... n_id=34526

Re: Hide price if 0

Posted: Sat Jul 27, 2019 3:08 am
by thekrotek
Not sure, what you mean, but in every template there's a check for price. Something like this:

{% if price %}

Which means, that if price zero or false then price section will not be displayed at all. The only issue I see here is zero price with decimals (e.g.: 0.00). In this case adding a single line to currency.php, as mentioned above, will do the trick. No extension needed at all, money wasted.

Re: Hide price if 0

Posted: Tue Jul 30, 2019 6:46 am
by MeckerOpa
Thanks, learned something again... Sometimes I have to waste money to get some know how :D
I have to learn the twig language. There are many functions I don't know right now. ???

Re: Hide price if 0

Posted: Tue Jul 30, 2019 6:59 am
by thekrotek
MeckerOpa wrote:
Tue Jul 30, 2019 6:46 am
I have to learn the twig language. There are many functions I don't know right now. ???
TWIG is shit, don't clog your head with it too much.