Skip to content

Commit b1390f8

Browse files
committed
[OpeningHours] Added Schema Controls
1 parent 4788bcf commit b1390f8

File tree

1 file changed

+61
-19
lines changed

1 file changed

+61
-19
lines changed

widgets/opening-hours.php

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ protected function _register_controls() {
361361
]
362362
);
363363

364+
$this->add_control(
365+
'enable_schema',
366+
[
367+
'label' => __( 'Enable openingHours Schema', 'mighty' ),
368+
'type' => Controls_Manager::SWITCHER,
369+
'label_on' => __( 'On', 'mighty' ),
370+
'label_off' => __( 'Off', 'mighty' ),
371+
'return_value' => 'yes',
372+
'default' => 'false'
373+
]
374+
);
375+
376+
$this->add_control(
377+
'schema_type',
378+
[
379+
'label' => __( 'Type', 'mighty' ),
380+
'type' => \Elementor\Controls_Manager::SELECT,
381+
'default' => 'solid',
382+
'options' => [
383+
'CivicStructure' => __( 'CivicStructure', 'mighty' ),
384+
'LocalBusiness' => __( 'LocalBusiness', 'mighty' ),
385+
],
386+
'default' => 'LocalBusiness',
387+
'description' => '<b>CivicStructure</b>: A public structure, such as a town hall or concert hall.<br>
388+
<b>LocalBusiness</b>:A particular physical business or branch of an organization.',
389+
'condition' => [
390+
'enable_schema' => 'yes'
391+
]
392+
]
393+
);
394+
364395
$this->end_controls_section();
365396

366397
$this->start_controls_section(
@@ -792,43 +823,54 @@ protected function render() {
792823
if ( empty( $settings[ 'mt_openinghours_data'] ) ) {
793824
return;
794825
}
826+
$enableSchema = $settings['enable_schema'] == "yes" ? true : false;
827+
$schemaType = $settings['schema_type'];
795828
?>
796-
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/CivicStructure" class="ma-openinghours-wrapper">
829+
830+
<div class="ma-openinghours-wrapper" <?php echo $enableSchema ? ' itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/' . $schemaType . '"' : ''; ?>>
797831

832+
<?php if ( $enableSchema && $settings['schema_type'] == "LocalBusiness" ) : ?>
798833
<img style="display:none;" itemprop="image" src="http://via.placeholder.com/350x150" alt="test logo" />
834+
<?php endif; ?>
799835

800-
<div itemprop="name" class="ma-oh-header"><?php echo $settings['header_text']; ?></div>
836+
<div <?php echo $enableSchema ? 'itemprop="name"' : ''; ?> class="ma-oh-header"><?php echo $settings['header_text']; ?></div>
801837

802838
<div class="ma-oh-rows">
803839
<?php foreach ( $settings['mt_openinghours_data'] as $item ) :
804840
$closingTime = $item['opening_business_time'] === "Closed" || $item['opening_business_time'] === "24 hours" ? false : true;
805-
$schemaDay = "";
806-
switch( $item['business_day'] ) {
807-
case 'All Days': $schemaDay = "Mo-Su";
808-
break;
809-
case 'Monday - Friday': $schemaDay = "Mo-Fr";
810-
break;
811-
case 'Saturday - Sunday': $schemaDay = "Sa-Su";
812-
break;
813-
default: $schemaDay = substr($item['business_day'], 0, 2);
841+
if ( $enableSchema ) {
842+
$schemaDay = "";
843+
switch( $item['business_day'] ) {
844+
case 'All Days': $schemaDay = "Mo-Su";
845+
break;
846+
case 'Monday - Friday': $schemaDay = "Mo-Fr";
847+
break;
848+
case 'Saturday - Sunday': $schemaDay = "Sa-Su";
849+
break;
850+
default: $schemaDay = substr($item['business_day'], 0, 2);
851+
}
814852
}
815853
?>
816854
<div class="ma-oh-row <?php echo ($settings['striped_effect'] == true) ? 'mt-striped' : ''; ?> elementor-repeater-item-<?php echo $item['_id']; ?>">
817855
<div class="ma-oh-day">
818-
<time itemprop="openingHours" datetime="<?php echo $schemaDay; ?>"><?php echo $item['business_day']; ?></time>.
856+
<time <?php echo $enableSchema ? 'itemprop="openingHours" datetime="'. $schemaDay .'"' : ''; ?>><?php echo $item['business_day']; ?></time>
819857
</div>
820858

821-
<div class="ma-oh-time" itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
859+
<div class="ma-oh-time" <?php echo $enableSchema ? 'itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification"' : ''; ?>>
822860
<?php if ( $item['opening_business_time'] === "24 hours" ) { ?>
823861

824-
<time itemprop="opens" content="<?php echo date("H:i", strtotime("12:00 AM")); ?>"><?php echo $item['opening_business_time']; ?></time>
862+
<time <?php echo $enableSchema ? 'itemprop="opens" content="' . date("H:i", strtotime("12:00 AM")) . '"' : ''; ?>><?php echo $item['opening_business_time']; ?></time>
825863

826-
<time itemprop='closes' content='<?php echo date("H:i", strtotime("12:00 PM")); ?>'></time>
864+
<?php if ( $enableSchema ) : ?>
865+
<time itemprop="closes" content="<?php echo date("H:i", strtotime("12:00 PM")); ?>"></time>
866+
<?php endif; ?>
827867

828868
<?php } else { ?>
829-
<time itemprop="opens" content="<?php echo date("H:i", strtotime($item['opening_business_time'])); ?>"><?php echo $item['opening_business_time']; ?></time>
830-
831-
<?php echo $closingTime ? " - <time itemprop='closes' content='". date("H:i", strtotime($item['closing_business_time'])) ."'>". $item['closing_business_time'] ."</time>" : '';
869+
<time <?php echo $enableSchema ? 'itemprop="opens" content="' . date("H:i", strtotime($item['opening_business_time'])) . '"' : ''; ?>><?php echo $item['opening_business_time']; ?></time>
870+
871+
<?php if ( $closingTime ) : ?>
872+
- <time <?php echo $enableSchema ? 'itemprop="closes" content="' . date("H:i", strtotime($item['closing_business_time'])) . '"' : ''; ?>><?php echo $item['closing_business_time']; ?></time>
873+
<?php endif;
832874
} ?>
833875

834876
</div>
@@ -837,7 +879,7 @@ protected function render() {
837879
<?php endforeach; ?>
838880
</div>
839881

840-
<div itemprop="description" class="ma-oh-footer"><?php echo $settings['footer_text']; ?></div>
882+
<div <?php echo $enableSchema ? 'itemprop="description"' : ''; ?> class="ma-oh-footer"><?php echo $settings['footer_text']; ?></div>
841883

842884
</div>
843885
<?php

0 commit comments

Comments
 (0)