Show custom field in product page if it meets the conditions

  • Posts: 208
  • Thank you received: 23
  • Hikamarket Multivendor Hikashop Business
1 year 10 months ago #332822

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


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

Thank you!

Last edit: 1 year 10 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: 78298
  • Thank you received: 12367
1 year 10 months ago #332823


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:
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.054 seconds
Powered by Kunena Forum