Show custom field in product page if it meets the conditions

  • Posts: 231
  • Thank you received: 28
  • Hikashop Business
3 years 6 months ago #332822

-- HikaShop version -- : 4.4.2
-- Joomla version -- : 3.9.26

Hi,

I have a custom field that I want to be visible on the product page, in a specific position, not where custom fields block's section exist's.
So I was wandering if what I did it is a good practice or I should do it in a nother way.

This code it's in thew my view: product / show_default.php

$sample_link_Config = hikashop_get('class.field')->getField('sample_link', 'product');
            $frontDisplay = array_filter(explode(';', $sample_link_Config->field_display));
//  field_display = ";compare=0;front_listing=0;back_invoice=0;back_shipping_invoice=0;order_form=0;(etc.);"

            if (in_array('front_listing=1', $frontDisplay) && $sample_link_Config->field_published) :
                if (isset($this->element->evscloud_link) && $this->element->sample_link != ''): ?>
                    <a class="hikabtn evs-sample" href="<?php echo $this->element->sample_link; ?>"><span>Show content</span></a><?php
                endif;
            endif;

Thank you!

Last edit: 3 years 6 months ago by oxido. Reason: I've added some extra info for clarification

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
3 years 6 months ago #332823

Hi,

It's ok but only if your custom field doesn't have / need translations and it's not a selector custom field (multiple dropdown, single dropdown, radio, checkbox, date picker, AJAX file, AJAX image, etc).
Otherwise, you need to do it like that:
$this->fieldsClass->show($sample_link_Config,$this->element->sample_link);
That way, the system will properly map the value from the database to what is supposed to be displayed (so instead of getting the value of the selected value, you would see the title of the selected value for a radio/dropdown/checkbox custom field).
Also, since you're doing a customization and you already know that the custom field is published, etc, I wouldn't bother with the first if. But it can be nice if you've working on someone else's website and the custom field could potentially be unpublished or its display settings could change in the future.

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

Time to create page: 0.057 seconds
Powered by Kunena Forum