get_billing_first_name() . ' ' . $order->get_billing_last_name() ); $desc = array(); foreach ( $order->get_items() as $item ) { $desc[] = $item->get_quantity() . '× ' . $item->get_name(); } $desc[] = ''; foreach ( dayslot_order_summary_rows( $order ) as $r ) { $desc[] = $r['label'] . ': ' . $r['value']; } $desc[] = __( 'Total', 'dayslot' ) . ': ' . wp_strip_all_tags( wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) ); $desc[] = __( 'Status', 'dayslot' ) . ': ' . wc_get_order_status_name( $order->get_status() ); if ( $order->get_billing_phone() ) { $desc[] = __( 'Phone', 'dayslot' ) . ': ' . $order->get_billing_phone(); } if ( $order->get_customer_note() ) { $desc[] = __( 'Note', 'dayslot' ) . ': ' . $order->get_customer_note(); } $desc[] = ''; $desc[] = $order->get_edit_order_url(); $pickup = 'pickup' === $row['mode']; $address = $order->has_shipping_address() ? implode( ', ', array_filter( array( $order->get_shipping_address_1(), $order->get_shipping_address_2(), $order->get_shipping_postcode(), $order->get_shipping_city() ) ) ) : implode( ', ', array_filter( array( $order->get_billing_address_1(), $order->get_billing_address_2(), $order->get_billing_postcode(), $order->get_billing_city() ) ) ); $modified = $order->get_date_modified(); $items[] = array( 'uid' => 'dys-order-' . $order->get_id(), 'date' => $row['date'], 'slot' => $row['slot'], 'variant' => isset( $row['variant'] ) ? $row['variant'] : '', 'summary' => ( $pickup ? '⇱ ' : '' ) . '#' . $order->get_order_number() . ( $name ? ' ' . $name : '' ), 'location' => $pickup ? '' : $address, 'description' => implode( "\n", $desc ), 'url' => $order->get_edit_order_url(), 'modified' => $modified ? $modified->getTimestamp() : 0, ); } return apply_filters( 'dayslot_ical_items', $items, $start, $end ); } function dayslot_output_ical() { $s = dayslot_get_settings(); $today = dayslot_today(); $start = $today->modify( '-90 days' )->format( 'Y-m-d' ); $end = $today->modify( '+' . max( 365, (int) $s['max_days'] ) . ' days' )->format( 'Y-m-d' ); $host = wp_parse_url( home_url(), PHP_URL_HOST ); $now = gmdate( 'Ymd\THis\Z' ); $lines = array( 'BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//Creonix//Dayslot//EN', 'CALSCALE:GREGORIAN', 'METHOD:PUBLISH', 'X-WR-CALNAME:' . dayslot_ical_text( get_bloginfo( 'name' ) . ' – ' . __( 'orders', 'dayslot' ) ), 'X-WR-TIMEZONE:' . wp_timezone_string(), 'REFRESH-INTERVAL;VALUE=DURATION:PT1H', 'X-PUBLISHED-TTL:PT1H', ); foreach ( dayslot_ical_items( $start, $end ) as $item ) { if ( ! dayslot_parse_date( $item['date'] ) ) { continue; } $lines[] = 'BEGIN:VEVENT'; $lines[] = 'UID:' . $item['uid'] . '@' . $host; $lines[] = 'DTSTAMP:' . $now; if ( ! empty( $item['modified'] ) ) { $lines[] = 'LAST-MODIFIED:' . gmdate( 'Ymd\THis\Z', $item['modified'] ); } foreach ( dayslot_ical_times( $item['date'], $item['slot'], isset( $item['variant'] ) ? $item['variant'] : '' ) as $line ) { $lines[] = $line; } $lines[] = 'SUMMARY:' . dayslot_ical_text( $item['summary'] ); if ( ! empty( $item['location'] ) ) { $lines[] = 'LOCATION:' . dayslot_ical_text( $item['location'] ); } $lines[] = 'DESCRIPTION:' . dayslot_ical_text( $item['description'] ); if ( ! empty( $item['url'] ) ) { $lines[] = 'URL:' . $item['url']; } $lines[] = 'STATUS:CONFIRMED'; $lines[] = 'END:VEVENT'; } $lines[] = 'END:VCALENDAR'; nocache_headers(); header( 'Content-Type: text/calendar; charset=utf-8' ); header( 'Content-Disposition: inline; filename="orders.ics"' ); header( 'X-Robots-Tag: noindex' ); foreach ( $lines as $line ) { echo dayslot_ical_fold( $line ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- iCal text, escaped by dayslot_ical_text(). } } /** * "Calendar sync" tab. */ function dayslot_render_ical_settings( $s ) { ?>