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