Post by MeckerOpa » Fri Jul 26, 2019 8:19 am

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.

Newbie

Posts

Joined
Sat Jun 27, 2015 12:21 am

Post by letxobnav » Fri Jul 26, 2019 4:02 pm

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.

Crystal Light Centrum Taiwan
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


Active Member
Online

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by MeckerOpa » Sat Jul 27, 2019 2:45 am

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

Newbie

Posts

Joined
Sat Jun 27, 2015 12:21 am

Post by thekrotek » Sat Jul 27, 2019 3:08 am

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.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by MeckerOpa » Tue Jul 30, 2019 6:46 am

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. ???

Newbie

Posts

Joined
Sat Jun 27, 2015 12:21 am

Post by thekrotek » Tue Jul 30, 2019 6:59 am

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.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am

Who is online

Users browsing this forum: No registered users and 13 guests