announcements
4 years ago
assignments
4 years ago
elements
4 years ago
enrolled-courses
4 years ago
instructor
3 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
3 years ago
withdraw-method-fields
4 years ago
announcements.php
4 years ago
assignments.php
4 years ago
create-course.php
3 years ago
dashboard.php
3 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
3 years ago
purchase_history.php
200 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 | if ( '' !== $start_date ) { |
| 20 | $start_date = tutor_get_formated_date( 'Y-m-d', $start_date ); |
| 21 | } |
| 22 | |
| 23 | if ( '' !== $end_date ) { |
| 24 | $end_date = tutor_get_formated_date( 'Y-m-d', $end_date ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Prepare filter period buttons |
| 29 | * |
| 30 | * Array structure is required as below |
| 31 | * |
| 32 | * @since 2.0.0 |
| 33 | */ |
| 34 | $filter_period = array( |
| 35 | array( |
| 36 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=today' ), |
| 37 | 'title' => __( 'Today', 'tutor' ), |
| 38 | 'type' => 'today' |
| 39 | ), |
| 40 | array( |
| 41 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=monthly' ), |
| 42 | 'title' => __( 'Monthly', 'tutor' ), |
| 43 | 'type' => 'monthly' |
| 44 | ), |
| 45 | array( |
| 46 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=yearly' ), |
| 47 | 'title' => __( 'Yearly', 'tutor' ), |
| 48 | 'type' => 'yearly' |
| 49 | ), |
| 50 | ); |
| 51 | |
| 52 | /** |
| 53 | * Calendar date buttons |
| 54 | * |
| 55 | * Array structure is required as below |
| 56 | * |
| 57 | * @since 2.0.0 |
| 58 | */ |
| 59 | |
| 60 | $filter_period_calendar = array( |
| 61 | 'filter_period' => $filter_period, |
| 62 | 'filter_calendar' => true |
| 63 | ); |
| 64 | |
| 65 | $filter_period_calendar_template = tutor()->path . 'views/elements/purchase-history-filter.php'; |
| 66 | tutor_load_template_from_custom_path( $filter_period_calendar_template, $filter_period_calendar ); |
| 67 | |
| 68 | $orders = tutor_utils()->get_orders_by_user_id( $user_id, $time_period, $start_date, $end_date, $offset, $per_page ); |
| 69 | $total_orders = tutor_utils()->get_total_orders_by_user_id( $user_id, $time_period, $start_date, $end_date ); |
| 70 | $monetize_by = tutor_utils()->get_option( 'monetize_by' ); |
| 71 | |
| 72 | ?> |
| 73 | |
| 74 | <div class="tutor-purchase-history"> |
| 75 | <?php if ( tutor_utils()->count( $orders ) ) : ?> |
| 76 | <div class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-24"><?php esc_html_e( 'Order History', 'tutor' ); ?></div> |
| 77 | <div class="tutor-table-responsive"> |
| 78 | <table class="tutor-table"> |
| 79 | <thead> |
| 80 | <th width="10%"> |
| 81 | <?php esc_html_e( 'Order ID', 'tutor' ); ?> |
| 82 | </th> |
| 83 | <th width="45%"> |
| 84 | <?php esc_html_e( 'Course Name', 'tutor' ); ?> |
| 85 | </th> |
| 86 | <th> |
| 87 | <?php esc_html_e( 'Date', 'tutor' ); ?> |
| 88 | </th> |
| 89 | <th> |
| 90 | <?php esc_html_e( 'Price', 'tutor' ); ?> |
| 91 | </th> |
| 92 | <th> |
| 93 | <?php esc_html_e( 'Status', 'tutor' ); ?> |
| 94 | </th> |
| 95 | <th></th> |
| 96 | </thead> |
| 97 | |
| 98 | <tbody> |
| 99 | <?php foreach ( $orders as $order ) : ?> |
| 100 | <?php |
| 101 | if ( $monetize_by === 'wc' ) { |
| 102 | $wc_order = wc_get_order( $order->ID ); |
| 103 | $price = tutor_utils()->tutor_price( $wc_order->get_total() ); |
| 104 | $raw_price = $wc_order->get_total(); |
| 105 | $status = $order->post_status; |
| 106 | $badge_class = 'primary'; |
| 107 | $order_status_text = ''; |
| 108 | |
| 109 | switch ( $status ) { |
| 110 | case 'wc-completed' === $status: |
| 111 | $badge_class = 'success'; |
| 112 | $order_status_text = __( 'Completed', 'tutor' ); |
| 113 | break; |
| 114 | case 'wc-processing' === $status: |
| 115 | $badge_class = 'warning'; |
| 116 | $order_status_text = __( 'Processing', 'tutor' ); |
| 117 | break; |
| 118 | case 'wc-on-hold' === $status: |
| 119 | $badge_class = 'warning'; |
| 120 | $order_status_text = __( 'On Hold', 'tutor' ); |
| 121 | break; |
| 122 | case 'wc-refunded' === $status: |
| 123 | $badge_class = 'danger'; |
| 124 | $order_status_text = __( 'Processing', 'tutor' ); |
| 125 | break; |
| 126 | case 'wc-cancelled' === $status: |
| 127 | $badge_class = 'danger'; |
| 128 | $order_status_text = __( 'Cancelled', 'tutor' ); |
| 129 | break; |
| 130 | case 'wc-pending' === $status: |
| 131 | $badge_class = 'warning'; |
| 132 | $order_status_text = __( 'Pending', 'tutor' ); |
| 133 | break; |
| 134 | } |
| 135 | } else if ( $monetize_by === 'edd' ) { |
| 136 | $edd_order = edd_get_payment( $order->ID ); |
| 137 | $price = edd_currency_filter( edd_format_amount( $edd_order->total ), edd_get_payment_currency_code( $order->ID ) ); |
| 138 | $raw_price = $edd_order->total; |
| 139 | $status = $edd_order->status_nicename; |
| 140 | $badge_class = 'primary'; |
| 141 | $order_status_text = $status; |
| 142 | } |
| 143 | ?> |
| 144 | <tr> |
| 145 | <td> |
| 146 | #<?php esc_html_e( $order->ID ); ?> |
| 147 | </td> |
| 148 | |
| 149 | <td> |
| 150 | <?php |
| 151 | $courses = tutor_utils()->get_course_enrolled_ids_by_order_id( $order->ID ); |
| 152 | if ( tutor_utils()->count( $courses ) ) { |
| 153 | foreach ( $courses as $course ) { |
| 154 | echo '<div>' . esc_html( get_the_title( $course['course_id'] ) ) . '</div>'; |
| 155 | } |
| 156 | } |
| 157 | ?> |
| 158 | </td> |
| 159 | |
| 160 | <td> |
| 161 | <?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->post_date ) ); ?> |
| 162 | </td> |
| 163 | |
| 164 | <td> |
| 165 | <?php echo wp_kses_post( $price ); ?> |
| 166 | </td> |
| 167 | |
| 168 | <td> |
| 169 | <span class="tutor-badge-label label-<?php esc_attr_e( $badge_class ); ?> tutor-m-4"><?php esc_html_e( $order_status_text ); ?></span> |
| 170 | </td> |
| 171 | |
| 172 | <td> |
| 173 | <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 ); ?>"> |
| 174 | <span class="tutor-icon-receipt-line" area-hidden="true"></span> |
| 175 | </a> |
| 176 | </td> |
| 177 | </tr> |
| 178 | <?php endforeach; ?> |
| 179 | </tbody> |
| 180 | </table> |
| 181 | </div> |
| 182 | |
| 183 | <?php |
| 184 | $pagination_data = array( |
| 185 | 'total_items' => ! empty( $total_orders ) ? count( $total_orders ) : 0, |
| 186 | 'per_page' => $per_page, |
| 187 | 'paged' => $paged, |
| 188 | ); |
| 189 | |
| 190 | $total_page = ceil($pagination_data['total_items'] / $pagination_data['per_page']); |
| 191 | |
| 192 | if( $total_page > 1 ) { |
| 193 | $pagination_template = tutor()->path . 'templates/dashboard/elements/pagination.php'; |
| 194 | tutor_load_template_from_custom_path( $pagination_template, $pagination_data ); |
| 195 | } |
| 196 | ?> |
| 197 | <?php else : ?> |
| 198 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 199 | <?php endif; ?> |
| 200 | </div> |