- Posts: 85
- Thank you received: 9
Add conditions to custom fields
- pagemaster
-
Topic Author
- Offline
Less
More
6 years 4 months ago - 6 years 52 minutes ago #320494
by pagemaster
Add conditions to custom fields was created by pagemaster
-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.2.26
Hello,
I created a custom field where there is a Dropdown menu (see in attach) where it`s possible to select the delivery hours, but I want to display only the hours from now to the end of the day. Is it possible to manage this directly to the back end component or I have to modify the code?
Thank you for your support
Best regards
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.2.26
Hello,
I created a custom field where there is a Dropdown menu (see in attach) where it`s possible to select the delivery hours, but I want to display only the hours from now to the end of the day. Is it possible to manage this directly to the back end component or I have to modify the code?
Thank you for your support
Best regards
Last edit: 6 years 52 minutes ago by pagemaster.
Please Log in or Create an account to join the conversation.
6 years 4 months ago #320497
by nicolas
Replied by nicolas on topic Add conditions to custom fields
Hi,
That will require developing a plugin to add a new type of custom field based on the single dropdown type but with a dynamic calculation of the choices available.
You can't do that with the options available by default.
That will require developing a plugin to add a new type of custom field based on the single dropdown type but with a dynamic calculation of the choices available.
You can't do that with the options available by default.
Please Log in or Create an account to join the conversation.
- pagemaster
-
Topic Author
- Offline
Less
More
- Posts: 85
- Thank you received: 9
6 years 52 minutes ago #325469
by pagemaster
Replied by pagemaster on topic Add conditions to custom fields
I solved with custom code.
This is the code of the view HikaShop - checkout / show_block_fields.php:
This is the code of the view HikaShop - checkout / show_block_fields.php:
Code:
if(empty($this->options['read_only'])) {
$onWhat = ($oneExtraField->field_type == 'radio') ? 'onclick' : 'onchange';
$stringShippingHours = explode("select", $this->fieldClass->display(
$oneExtraField,
false,
false,
false
));
?>
<?php if($_SESSION["nField"] == 0){ ?>
<select id="orariodconsegna" name="data[order_1_4][orariodconsegna]" size="1" class="hikashop_field_dropdown hkform-control" onchange="window.hikashop.toggleField(this.value,'orariodconsegna','order_1_4',0,'hikashop_');">
<?php
foreach($stringShippingHours as $stringShippingHour){
$tz = 'Europe/Rome';
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
$actualHour = $dt->format('H');
$nextHour = $actualHour + 1;
if($nextHour < 10){
$nextHour = '0' . $nextHour;
}
$fromNow = explode($actualHour . ':00-' . $nextHour . ':00</option>', $stringShippingHour);
echo $fromNow[1] . '<br>';
}
?>
</select>
<?php } ?>
<?php
}else{
echo $this->fieldClass->show($oneExtraField, @$cart->cart_fields->$fieldName);
}
?>
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.047 seconds