announcements
4 years ago
assignments
4 years ago
elements
4 years ago
enrolled-courses
4 years ago
instructor
4 years ago
my-courses
4 years ago
my-quiz-attempts
4 years ago
notifications
4 years ago
question-answer
4 years ago
quiz-attempts
4 years ago
reviews
4 years ago
settings
4 years ago
withdraw-method-fields
4 years ago
announcements.php
4 years ago
assignments.php
4 years ago
create-course.php
4 years ago
dashboard.php
4 years ago
enrolled-courses.php
4 years ago
index.php
4 years ago
logged-in.php
4 years ago
my-courses.php
4 years ago
my-profile.php
4 years ago
my-quiz-attempts.php
4 years ago
purchase_history.php
4 years ago
question-answer.php
4 years ago
quiz-attempts.php
4 years ago
registration.php
4 years ago
reviews.php
4 years ago
settings.php
4 years ago
wishlist.php
4 years ago
withdraw.php
4 years ago
purchase_history.php
221 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Purchase history |
| 4 | * @package TutorLMS/Templates |
| 5 | * @version 1.4.3 |
| 6 | */ |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | //global variables |
| 11 | $user_id = get_current_user_id(); |
| 12 | $time_period = $active = isset( $_GET['period'] ) ? $_GET['period'] : ''; |
| 13 | $start_date = isset( $_GET['start_date']) ? sanitize_text_field( $_GET['start_date'] ) : ''; |
| 14 | $end_date = isset( $_GET['end_date']) ? sanitize_text_field( $_GET['end_date'] ) : ''; |
| 15 | |
| 16 | $paged = ( isset( $_GET['current_page'] ) && is_numeric( $_GET['current_page'] ) && $_GET['current_page'] >= 1 ) ? $_GET['current_page'] : 1; |
| 17 | $per_page = tutor_utils()->get_option( 'pagination_per_page', 10 ); |
| 18 | $offset = ( $per_page * $paged ) - $per_page; |
| 19 | |
| 20 | if ( '' !== $start_date ) { |
| 21 | $start_date = tutor_get_formated_date( 'Y-m-d', $start_date ); |
| 22 | } |
| 23 | if ( '' !== $end_date ) { |
| 24 | $end_date = tutor_get_formated_date( 'Y-m-d', $end_date ); |
| 25 | } |
| 26 | ?> |
| 27 | |
| 28 | <div class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-24"><?php esc_html_e( 'Order History', 'tutor' ); ?></div> |
| 29 | <div class="tutor-purchase-history"> |
| 30 | <!--filter buttons tabs--> |
| 31 | <?php |
| 32 | /** |
| 33 | * Prepare filter period buttons |
| 34 | * |
| 35 | * Array structure is required as below |
| 36 | * |
| 37 | * @since 2.0.0 |
| 38 | */ |
| 39 | $filter_period = array( |
| 40 | array( |
| 41 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=today' ), |
| 42 | 'title' => __( 'Today', 'tutor' ), |
| 43 | 'type' => 'today' |
| 44 | ), |
| 45 | array( |
| 46 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=monthly' ), |
| 47 | 'title' => __( 'Monthly', 'tutor' ), |
| 48 | 'type' => 'monthly' |
| 49 | ), |
| 50 | array( |
| 51 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=yearly' ), |
| 52 | 'title' => __( 'Yearly', 'tutor' ), |
| 53 | 'type' => 'yearly' |
| 54 | ), |
| 55 | ); |
| 56 | |
| 57 | /** |
| 58 | * Calendar date buttons |
| 59 | * |
| 60 | * Array structure is required as below |
| 61 | * |
| 62 | * @since 2.0.0 |
| 63 | */ |
| 64 | |
| 65 | $filter_period_calendar = array( |
| 66 | 'filter_period' => $filter_period, |
| 67 | 'filter_calendar' => true |
| 68 | ); |
| 69 | |
| 70 | $filter_period_calendar_template = tutor()->path . 'views/elements/purchase-history-filter.php'; |
| 71 | tutor_load_template_from_custom_path( $filter_period_calendar_template, $filter_period_calendar ); |
| 72 | |
| 73 | $orders = tutor_utils()->get_orders_by_user_id( $user_id, $time_period, $start_date, $end_date, $offset, $per_page ); |
| 74 | $total_orders = tutor_utils()->get_total_orders_by_user_id( $user_id, $time_period, $start_date, $end_date ); |
| 75 | $monetize_by = tutor_utils()->get_option( 'monetize_by' ); |
| 76 | |
| 77 | ?> |
| 78 | <!--filter button tabs end--> |
| 79 | </div> |
| 80 | |
| 81 | <!-- Purchase history table --> |
| 82 | <div class="tutor-table-wrapper"> |
| 83 | <table class="tutor-table tutor-table-responsive tutor-table-purchase-history"> |
| 84 | <?php if ( tutor_utils()->count ( $orders ) ) { ?> |
| 85 | <thead class="tutor-fs-7 tutor-fw-medium"> |
| 86 | <th> |
| 87 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 88 | <?php esc_html_e( 'Order ID', 'tutor' ); ?> |
| 89 | </div> |
| 90 | </th> |
| 91 | <th> |
| 92 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 93 | <?php esc_html_e( 'Course Name', 'tutor' ); ?> |
| 94 | </div> |
| 95 | </th> |
| 96 | <th> |
| 97 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 98 | <?php esc_html_e( 'Date', 'tutor' ); ?> |
| 99 | </div> |
| 100 | </th> |
| 101 | <th> |
| 102 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 103 | <?php esc_html_e( 'Price', 'tutor' ); ?> |
| 104 | </div> |
| 105 | </th> |
| 106 | <th> |
| 107 | <div class="tutor-fs-7 tutor-color-secondary"> |
| 108 | <?php esc_html_e( 'Status', 'tutor' ); ?> |
| 109 | </div> |
| 110 | </th> |
| 111 | <th class="tutor-shrink"></th> |
| 112 | </thead> |
| 113 | <?php } ?> |
| 114 | <tbody> |
| 115 | <?php |
| 116 | if ( tutor_utils()->count ( $orders ) ) { |
| 117 | foreach ( $orders as $order ) { |
| 118 | if ( $monetize_by === 'wc' ) { |
| 119 | $wc_order = wc_get_order( $order->ID ); |
| 120 | $price = tutor_utils()->tutor_price( $wc_order->get_total() ); |
| 121 | $raw_price = $wc_order->get_total(); |
| 122 | $status = $order->post_status; |
| 123 | $badge_class = 'primary'; |
| 124 | $order_status_text = ''; |
| 125 | switch ( $status ) { |
| 126 | case 'wc-completed' === $status: |
| 127 | $badge_class = 'success'; |
| 128 | $order_status_text = __( 'Completed', 'tutor' ); |
| 129 | break; |
| 130 | case 'wc-processing' === $status: |
| 131 | $badge_class = 'warning'; |
| 132 | $order_status_text = __( 'Processing', 'tutor' ); |
| 133 | break; |
| 134 | case 'wc-on-hold' === $status: |
| 135 | $badge_class = 'warning'; |
| 136 | $order_status_text = __( 'On Hold', 'tutor' ); |
| 137 | break; |
| 138 | case 'wc-refunded' === $status: |
| 139 | $badge_class = 'danger'; |
| 140 | $order_status_text = __( 'Processing', 'tutor' ); |
| 141 | break; |
| 142 | case 'wc-cancelled' === $status: |
| 143 | $badge_class = 'danger'; |
| 144 | $order_status_text = __( 'Cancelled', 'tutor' ); |
| 145 | break; |
| 146 | case 'wc-pending' === $status: |
| 147 | $badge_class = 'warning'; |
| 148 | $order_status_text = __( 'Pending', 'tutor' ); |
| 149 | break; |
| 150 | } |
| 151 | } else if ( $monetize_by === 'edd' ) { |
| 152 | $edd_order = edd_get_payment( $order->ID ); |
| 153 | $price = edd_currency_filter( edd_format_amount( $edd_order->total ), edd_get_payment_currency_code( $order->ID ) ); |
| 154 | $raw_price = $edd_order->total; |
| 155 | $status = $edd_order->status_nicename; |
| 156 | $badge_class = 'primary'; |
| 157 | $order_status_text = $status; |
| 158 | } |
| 159 | |
| 160 | ?> |
| 161 | <tr> |
| 162 | <td data-th="Order ID" class="v-align-top"> |
| 163 | <div class="td-course tutor-fs-6 tutor-fw-medium tutor-color-black tutor-mt-4" style="font-weight: 600;"> |
| 164 | #<?php esc_html_e( $order->ID ); ?> |
| 165 | </div> |
| 166 | </td> |
| 167 | <td data-th="Course Name"> |
| 168 | <?php |
| 169 | $courses = tutor_utils()->get_course_enrolled_ids_by_order_id( $order->ID ); |
| 170 | if ( tutor_utils()->count( $courses ) ) { |
| 171 | foreach ( $courses as $course ) { |
| 172 | echo '<div class="tutor-fs-7 tutor-fw-medium tutor-color-black">' . esc_html( get_the_title( $course['course_id'] ) ) . '</div>'; |
| 173 | } |
| 174 | } |
| 175 | ?> |
| 176 | </td> |
| 177 | <td data-th="Date"> |
| 178 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->post_date ) ); ?></span> |
| 179 | </td> |
| 180 | <td data-th="Price"> |
| 181 | <span class="tutor-fs-7 tutor-fw-medium tutor-color-black"><?php echo wp_kses_post( $price ); ?></span> |
| 182 | </td> |
| 183 | <td data-th="Status"> |
| 184 | <span class="tutor-badge-label label-<?php esc_attr_e( $badge_class ); ?> tutor-m-4"><?php esc_html_e( $order_status_text ); ?></span> |
| 185 | </td> |
| 186 | <td data-th="Download"> |
| 187 | <a href="javascript:;" class="tutor-export-purchase-history tutor-iconic-btn tutor-iconic-btn-secondary" data-order="<?php echo esc_attr( $order->ID ); ?>" data-course-name="<?php echo esc_attr( get_the_title( $course['course_id'] ) ); ?>" data-price="<?php echo esc_attr( $raw_price ); ?>" data-date="<?php echo esc_attr( date_i18n( get_option( 'date_format' ), strtotime( $order->post_date ) ) ); ?>" data-status="<?php echo esc_attr( $order_status_text ); ?>"> |
| 188 | <span class="tutor-icon-receipt-line" area-hidden="true"></span> |
| 189 | </a> |
| 190 | </td> |
| 191 | </tr> |
| 192 | <?php } ?> |
| 193 | <?php } else { ?> |
| 194 | <tr> |
| 195 | <td colspan="100%"> |
| 196 | <div class="td-empty-state"> |
| 197 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 198 | </div> |
| 199 | </td> |
| 200 | </tr> |
| 201 | <?php } ?> |
| 202 | </tbody> |
| 203 | </table> |
| 204 | <?php |
| 205 | /** |
| 206 | * Prepare pagination data & load template |
| 207 | */ |
| 208 | $pagination_data = array( |
| 209 | 'total_items' => ! empty( $total_orders ) ? count( $total_orders ) : 0, |
| 210 | 'per_page' => $per_page, |
| 211 | 'paged' => $paged, |
| 212 | ); |
| 213 | $total_page = ceil($pagination_data['total_items'] / $pagination_data['per_page']); |
| 214 | if($total_page > 1) { |
| 215 | $pagination_template = tutor()->path . 'templates/dashboard/elements/pagination.php'; |
| 216 | tutor_load_template_from_custom_path( $pagination_template, $pagination_data ); |
| 217 | } |
| 218 | ?> |
| 219 | </div> |
| 220 | |
| 221 |