Hide empty custom field from checkout cart

  • Posts: 1110
  • Thank you received: 12
  • Hikashop Business
1 day 8 hours ago #367836

-- HikaShop version -- : 6.0.0
-- Joomla version -- : 3.10.12

Hi!

I added two product custom fields to the checkout cart.
I want to ask if it's possible to hide them if they have no value.
For example one field is in some products but not the other is not, so they are both in the cart but one column looks empty.

Thank you!

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 84079
  • Thank you received: 13634
  • MODERATOR
1 day 2 hours ago #367843

Hi,

Try adding the code:

			if(!empty($this->extraFields['product'])) {
				$remove = [];
				$config = hikashop_config();
				$group = $config->get('group_options', 0);
				foreach($this->extraFields['product'] as $fieldname => $field) {
					$hide = true;
					foreach($products as $i => $product) {
						if(empty($product->cart_product_quantity))
							continue;
						if($group && !empty($product->cart_product_option_parent_id))
							continue;
						if(empty($product->$fieldname))
							continue;
						$hide = false;
					}
					if($hide) {
						$remove[] = $i;
					}
				}
				if(count($remove)) {
					foreach($remove as $k) {
						unset($this->extraFields['product'][$k]);
					}
				}
			}
after the line:
$this->extraFields['product'] = $this->fieldClass->getFields('display:checkout=1', $products, 'product');
in the file components/com_hikashop/views/checkout/view.html.php
It should hopefully do it.
We can include this code on our end for the next version if it works fine.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

Time to create page: 0.040 seconds
Powered by Kunena Forum