Date Custom fields

  • Posts: 53
  • Thank you received: 3
1 year 3 months ago #360484

-- HikaShop version -- : 5.0.4
-- Joomla version -- : 5.1.0
-- PHP version -- : 8.1

can you please assist on creating a radio buttons custom field on checkout page with dynamic valuse of 7 days i a row from tomorrow ?

suppose today is 4/22/2024

i need to create a custom field of type radio in checkout page with this values :

Tomorrow (4/23/2024)
The day after tomrrow (4/24/2024)
4/25/2024
4/26/2024
4/27/2024
4/28/2024
4/29/2024

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

  • Posts: 84149
  • Thank you received: 13652
  • MODERATOR
1 year 3 months ago #360486

Hi,

In the data area of your custom field, instead of entering values, you can provide a MySQL query.
There, you can provide a MySQL query to generate the dates.
For example:

SELECT CONCAT('Tomorrow (',DATE_FORMAT(CURDATE() + INTERVAL 1 DAY, '%d/%m/%Y'),')') as value UNION SELECT CONCAT('The day after tomorrow (',DATE_FORMAT(CURDATE() + INTERVAL 2 DAY, '%d/%m/%Y'),')') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 3 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 4 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 5 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 6 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 7 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 8 DAY, '%d/%m/%Y');
References:
www.w3schools.com/sql/func_mysql_curdate.asp
www.w3schools.com/sql/func_mysql_date_format.asp
dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
www.w3schools.com/sql/func_mysql_concat.asp
dev.mysql.com/doc/refman/8.0/en/union.html

Last edit: 1 year 3 months ago by nicolas.
The following user(s) said Thank You: demoisellegol

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

  • Posts: 53
  • Thank you received: 3
2 days 1 hour ago #368039

is there any solution to display this dates with JDATE ?

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

  • Posts: 84149
  • Thank you received: 13652
  • MODERATOR
1 day 21 hours ago #368040

Hi,

Are you talking about JDate ?
docs.joomla.org/How_to_use_JDate
If so, I understand you're saying that you want to be able to use PHP code to generate the values selectable by the custom field. Is that so ?
It is possible but it's not as easy as the MySQL query solution I provided in my previous message. With the MySQL query, you just test the query you need via PHPMyAdmin or an online MySQL query testing website. Once you have the query, you can just copy / paste it in your field settings.

With PHP, you need to develop a plugin of the group "hikashop" and implement the "Field API" :
www.hikashop.com/support/documentation/6...entation.html#fields
With it, you can add your own type of custom field, have it extend the normal radio field class, and manually generate the values with your own PHP code and / or with JDate. An example of a plugin using this API to add a custom field type is in the folder plugins/hikashop/datepickerfield/
It adds the "Advanced Date Picker" custom field type to HikaShop.

As you probably understand, doing what you asked for as a custom plugin with the Field API and JDate is more complex and will take more time than the MySQL query, so I still recommand you to use the MySQL query solution.

The following user(s) said Thank You: demoisellegol

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

Time to create page: 0.059 seconds
Powered by Kunena Forum