Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/Dashboard/Templates/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@

// Check & make 12 hours format data for save.
$opening_timestamp = dokan_get_timestamp( $opening_time );
$opening_time = dokan_convert_date_format( $opening_time, wc_time_format(), 'g:i a' );
$opening_time = dokan_convert_date_format( $opening_time, 'g:i a', 'g:i a' );

// Check & make 12 hours format data for save.
$closing_timestamp = dokan_get_timestamp( $closing_time );
$closing_time = dokan_convert_date_format( $closing_time, wc_time_format(), 'g:i a' );
$closing_time = dokan_convert_date_format( $closing_time, 'g:i a', 'g:i a' );

// If our opening time is less than closing time.
if ( $opening_timestamp > $closing_timestamp ) {
Expand Down Expand Up @@ -864,7 +864,7 @@
*
* @return string
*/
public function get_method_frontend_title( $title, $method ) {

Check warning on line 867 in includes/Dashboard/Templates/Settings.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $method is never used
if ( 0 === stripos( $title, 'Dokan ' ) ) {
return substr( $title, 6 );
}
Expand Down
36 changes: 25 additions & 11 deletions templates/settings/store-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
// dokan store open close scripts starts //
var store_opencolse = $( '.store-open-close' );
store_opencolse.hide();

let timeFormatMoment = window.dokan_get_i18n_time_format().replace(/\\(.)/g, '[$1]');
$( '#dokan-store-time-enable' ).on( 'change', function() {
var self = $(this);

Expand Down Expand Up @@ -323,18 +323,25 @@
lang : dokan_helper.timepicker_locale,
minTime : '12:00 am',
maxTime : '11:30 pm',
timeFormat : '<?php echo esc_js( wc_time_format() ); ?>',
timeFormat : dokan_helper.i18n_time_format,
scrollDefault : 'now',
});

// Add validation for store time when changed.
$( '.dokan-store-times' ).on( 'change', '.dokan-form-group', function () {
const self = $( this ),
openValue = self.find( '.opening-time' ).val(),
closeValue = self.find( '.closing-time' ).val(),
formattedOpenValue = moment( openValue, 'hh:mm a' ).format( 'HH:mm' ),
formattedCloseValue = moment( closeValue, 'hh:mm a' ).format( 'HH:mm' );

const self = $( this ),
openValue = self.find( '.opening-time' ).val(),

Check warning on line 333 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
closeValue = self.find( '.closing-time' ).val(),

Check warning on line 334 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
$openInputHidden = self.find( '.opening-time-hidden' ),

Check warning on line 335 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
$closeInputHidden = self.find( '.closing-time-hidden' ),

Check warning on line 336 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
formattedOpenValue = moment( openValue, timeFormatMoment ).format( 'HH:mm' ),

Check warning on line 337 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
formattedCloseValue = moment( closeValue, timeFormatMoment ).format( 'HH:mm' );

Check warning on line 338 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.

let openValueSelected = moment( openValue, timeFormatMoment ).format('hh:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );

$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use 'h:mm a' format to match server-side expectations.

The 'hh:mm a' format outputs times with leading zeros (e.g., "09:30 am"), but the PHP backend uses 'g:i a' which expects no leading zeros (e.g., "9:30 am"). Use moment's single 'h' to avoid potential parsing issues.

Proposed fix
-                let openValueSelected  = moment( openValue, timeFormatMoment ).format('hh:mm a' );
-                let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );
+                let openValueSelected  = moment( openValue, timeFormatMoment ).format('h:mm a' );
+                let closeValueSelected = moment( closeValue, timeFormatMoment ).format('h:mm a' );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let openValueSelected = moment( openValue, timeFormatMoment ).format('hh:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );
$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
let openValueSelected = moment( openValue, timeFormatMoment ).format('h:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('h:mm a' );
$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
🤖 Prompt for AI Agents
In `@templates/settings/store-form.php` around lines 340 - 344, The client-side
time formatting currently uses moment(...).format('hh:mm a') for
openValueSelected and closeValueSelected which produces leading zeros; update
both calls to use format('h:mm a') to match the server-side PHP expectation
(ensure the two lines setting openValueSelected and closeValueSelected are
changed), so the values written via $openInputHidden.val(...) and
$closeInputHidden.val(...) will have no leading zero.

if ( formattedOpenValue > formattedCloseValue ) {
self.find( 'input.dokan-form-control' ).css({ 'border-color': '#F87171', 'color': '#F87171' });
} else {
Expand All @@ -345,7 +352,9 @@
$( 'input[name="dokan_update_store_settings"]' ).on( 'click', function ( e ) {
$( '.dokan-store-times' ).each( function () {
const self = $( this ),
open_or_close = self.find( '.dokan-on-off' ).val();
$openInputHidden = self.find( '.opening-time-hidden' ),

Check warning on line 355 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
$closeInputHidden = self.find( '.closing-time-hidden' ),

Check warning on line 356 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.
open_or_close = self.find( '.dokan-on-off' ).val();

Check warning on line 357 in templates/settings/store-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 2 spaces.

// check if today is open
if ( 'close' === open_or_close ) {
Expand All @@ -366,9 +375,14 @@
return false;
}

const formattedOpenValue = moment( openValue, 'hh:mm a' ).format( 'HH:mm' ),
formattedCloseValue = moment( closeValue, 'hh:mm a' ).format( 'HH:mm' );
const formattedOpenValue = moment( openValue, timeFormatMoment ).format( 'HH:mm' ),
formattedCloseValue = moment( closeValue, timeFormatMoment ).format( 'HH:mm' );

let openValueSelected = moment(openValue, timeFormatMoment ).format('hh:mm a');
let closeValueSelected = moment(closeValue, timeFormatMoment ).format('hh:mm a');

$openInputHidden.val(openValueSelected);
$closeInputHidden.val(closeValueSelected);
if ( formattedOpenValue >= formattedCloseValue ) {
self.find( 'input.dokan-form-control' ).css({ 'border-color': '#F87171', 'color': '#F87171' });
self.find( '.opening-time' ).focus();
Expand Down
14 changes: 10 additions & 4 deletions templates/settings/store-time.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="dokan-w6" style="width: auto">
<?php
foreach ( $dokan_days as $day_key => $day ) {
$status = isset( $store_info[ $day_key ]['status'] ) ? $store_info[ $day_key ]['status'] : '';

Check failure on line 5 in templates/settings/store-time.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Overriding WordPress globals is prohibited. Found assignment to $status
$status = isset( $store_info[ $day_key ]['open'] ) ? $store_info[ $day_key ]['open'] : $status;

Check failure on line 6 in templates/settings/store-time.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Overriding WordPress globals is prohibited. Found assignment to $status

$opening_time = dokan_get_store_times( $day_key, 'opening_time' );
$closing_time = dokan_get_store_times( $day_key, 'closing_time' );
Expand All @@ -24,16 +24,22 @@
</label>
<label for="opening-time[<?php echo esc_attr( $day_key ); ?>]" class="time" style="visibility: <?php echo isset( $status ) && $status === 'open' ? 'visible' : 'hidden'; ?>" >
<input type="text" class="dokan-form-control opening-time"
name="opening_time[<?php echo esc_attr( $day_key ); ?>]"
id="opening-time[<?php echo esc_attr( $day_key ); ?>]" placeholder="00:00"
value="<?php echo esc_attr( $opening_time ); ?>"/>
value="<?php echo $opening_time; ?>"/>
<input type="hidden"
name="opening_time[<?php echo esc_attr( $day_key ); ?>]"
class="opening-time-hidden"
value="<?php echo $opening_time; ?>"/>
</label>
<label for="closing-time[<?php echo esc_attr( $day_key ); ?>]" class="time" style="visibility: <?php echo isset( $status ) && $status === 'open' ? 'visible' : 'hidden'; ?>" >
<input type="text" class="dokan-form-control closing-time"
name="closing_time[<?php echo esc_attr( $day_key ); ?>]"
id="closing-time[<?php echo esc_attr( $day_key ); ?>]" placeholder="00:00"
value="<?php echo esc_attr( $closing_time === '11:59 pm' ? '11:30 pm' : $closing_time ); ?>"/>
</label>
<input type="hidden"
name="closing_time[<?php echo esc_attr( $day_key ); ?>]"
class="closing-time-hidden"
value="<?php echo esc_attr( $closing_time === '11:59 pm' ? '11:30 pm' : $closing_time ); ?>" />
</label>
</div>
</div>
<?php } ?>
Expand Down
Loading