Skip to content

Commit 519a446

Browse files
author
Chris Gårdenberg
committed
feat: Support for the required fields in Google Search Console for the ld+json
fixes #511
1 parent 9adb988 commit 519a446

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

content/template/data/ld-json.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,29 @@
4949
return;
5050
}
5151

52+
$prices = array();
53+
54+
if ( ! empty( $selected_course['PriceNames'] ) ) {
55+
foreach ( $selected_course['PriceNames'] as $pn ) {
56+
$prices[ (string) $pn['PriceNameId'] ] = $pn;
57+
}
58+
}
59+
5260
$org_name = trim( ! empty( $organization['LegalName'] ) ? $organization['LegalName'] : $organization['OrganisationName'] );
5361

54-
$events = null;
62+
$events = [];
63+
64+
$offers = [];
65+
66+
foreach ( $prices as $priceNameId => $priceName ) {
67+
$offers[] = [
68+
'@type' => 'Offer',
69+
'price' => $priceName['Price'],
70+
'category' => $priceName['Price'] == 0 ? 'Free' : 'Paid',
71+
'priceCurrency' => EDU()->get_option( 'eduadmin-currency', 'SEK' ),
72+
'name' => $priceName['PriceNameDescription'],
73+
];
74+
}
5575

5676
foreach ( $selected_course['Events'] as $event ) {
5777
$_event = [
@@ -63,10 +83,35 @@
6383
$_event['courseMode'] = "online";
6484
$_event['location'] = "Online";
6585
$_event['description'] = 'On-demand';
86+
87+
if ( $event['OnDemandAccessDays'] == null && $selected_course['OnDemandAccessDays'] != null ) {
88+
$event['OnDemandAccessDays'] = $selected_course['OnDemandAccessDays'];
89+
}
90+
91+
if ( $event['OnDemandAccessDays'] > 0 ) {
92+
$_event['courseSchedule'] = [
93+
'@type' => 'Schedule',
94+
'repeatFrequency' => 'Daily',
95+
'repeatCount' => $event['OnDemandAccessDays'],
96+
];
97+
} else {
98+
$_event['courseSchedule'] = [
99+
'@type' => 'Schedule',
100+
'duration' => 'P1D',
101+
'repeatFrequency' => 'Yearly',
102+
'repeatCount' => 99,
103+
];
104+
}
66105
} else {
67106
$_event['location'] = $event['City'];
68107
$_event['startDate'] = $event['StartDate'];
69108
$_event['endDate'] = $event['EndDate'];
109+
110+
$_event['courseSchedule'] = [
111+
'@type' => 'Schedule',
112+
'startDate' => $event['StartDate'],
113+
'endDate' => $event['EndDate'],
114+
];
70115
}
71116

72117
if ( ! empty( $event['MaxParticipantNumber'] ) && $event['MaxParticipantNumber'] > 0 ) {
@@ -93,6 +138,7 @@
93138
'image' => $organization['LogoUrl'],
94139
],
95140
'hasCourseInstance' => $events,
141+
'offers' => $offers,
96142
];
97143

98144
echo '<script type="application/ld+json">

0 commit comments

Comments
 (0)