Add conditions to custom fields

  • Posts: 85
  • Thank you received: 9
3 years 10 months ago #320494

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

Attachments:
Last edit: 3 years 5 months ago by pagemaster.

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

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
3 years 10 months ago #320497

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.

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

  • Posts: 85
  • Thank you received: 9
3 years 5 months ago #325469

I solved with custom code.

This is the code of the view HikaShop - checkout / show_block_fields.php:

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