announcements
3 years ago
assignments
2 years ago
elements
1 year ago
enrolled-courses
3 years ago
instructor
2 years ago
my-courses
3 years ago
my-quiz-attempts
3 years ago
notifications
3 years ago
question-answer
2 years ago
quiz-attempts
3 years ago
reviews
3 years ago
settings
1 year ago
withdraw-method-fields
3 years ago
announcements.php
1 year ago
assignments.php
1 year ago
create-course.php
1 year ago
dashboard.php
1 year ago
enrolled-courses.php
1 year ago
index.php
3 years ago
logged-in.php
3 years ago
my-courses.php
1 year ago
my-profile.php
3 years ago
my-quiz-attempts.php
3 years ago
purchase_history.php
1 year ago
question-answer.php
2 years ago
quiz-attempts.php
1 year ago
registration.php
2 years ago
reviews.php
3 years ago
settings.php
3 years ago
wishlist.php
1 year ago
withdraw.php
1 year ago
purchase_history.php
316 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\Ecommerce\Ecommerce; |
| 15 | use Tutor\Helpers\DateTimeHelper; |
| 16 | use TUTOR\Input; |
| 17 | use Tutor\Models\OrderModel; |
| 18 | |
| 19 | // Global variables. |
| 20 | $user_id = get_current_user_id(); |
| 21 | $active = Input::get( 'period', '' ); |
| 22 | $time_period = $active; |
| 23 | $start_date = Input::get( 'start_date', '' ); |
| 24 | $end_date = Input::get( 'end_date', '' ); |
| 25 | |
| 26 | $paged = Input::get( 'current_page', 1, Input::TYPE_INT ); |
| 27 | $per_page = tutor_utils()->get_option( 'pagination_per_page', 10 ); |
| 28 | $offset = ( $per_page * $paged ) - $per_page; |
| 29 | if ( '' !== $start_date ) { |
| 30 | $start_date = tutor_get_formated_date( 'Y-m-d', $start_date ); |
| 31 | } |
| 32 | |
| 33 | if ( '' !== $end_date ) { |
| 34 | $end_date = tutor_get_formated_date( 'Y-m-d', $end_date ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Prepare filter period buttons |
| 39 | * |
| 40 | * Array structure is required as below |
| 41 | * |
| 42 | * @since 2.0.0 |
| 43 | */ |
| 44 | $filter_period = array( |
| 45 | array( |
| 46 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=today' ), |
| 47 | 'title' => __( 'Today', 'tutor' ), |
| 48 | 'type' => 'today', |
| 49 | ), |
| 50 | array( |
| 51 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=monthly' ), |
| 52 | 'title' => __( 'Monthly', 'tutor' ), |
| 53 | 'type' => 'monthly', |
| 54 | ), |
| 55 | array( |
| 56 | 'url' => esc_url( tutor_utils()->tutor_dashboard_url() . 'purchase_history?period=yearly' ), |
| 57 | 'title' => __( 'Yearly', 'tutor' ), |
| 58 | 'type' => 'yearly', |
| 59 | ), |
| 60 | ); |
| 61 | |
| 62 | /** |
| 63 | * Calendar date buttons |
| 64 | * |
| 65 | * Array structure is required as below |
| 66 | * |
| 67 | * @since 2.0.0 |
| 68 | */ |
| 69 | |
| 70 | $filter_period_calendar = array( |
| 71 | 'filter_period' => $filter_period, |
| 72 | 'filter_calendar' => true, |
| 73 | ); |
| 74 | |
| 75 | ?> |
| 76 | <div class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-24"> |
| 77 | <?php esc_html_e( 'Order History', 'tutor' ); ?> |
| 78 | </div> |
| 79 | <?php |
| 80 | |
| 81 | $filter_period_calendar_template = tutor()->path . 'views/elements/purchase-history-filter.php'; |
| 82 | tutor_load_template_from_custom_path( $filter_period_calendar_template, $filter_period_calendar ); |
| 83 | |
| 84 | $orders = tutor_utils()->get_orders_by_user_id( $user_id, $time_period, $start_date, $end_date, $offset, $per_page ); |
| 85 | $total_orders = tutor_utils()->get_total_orders_by_user_id( $user_id, $time_period, $start_date, $end_date ); |
| 86 | $total_orders = ! empty( $total_orders ) ? count( $total_orders ) : 0; |
| 87 | |
| 88 | $monetize_by = tutor_utils()->get_option( 'monetize_by' ); |
| 89 | if ( Ecommerce::MONETIZE_BY === $monetize_by ) { |
| 90 | $response = ( new OrderModel() )->get_user_orders( $time_period, $start_date, $end_date, $user_id, $per_page, $offset ); |
| 91 | $orders = $response['results']; |
| 92 | $total_orders = $response['total_count']; |
| 93 | } |
| 94 | ?> |
| 95 | |
| 96 | <div class="tutor-purchase-history"> |
| 97 | <?php if ( tutor_utils()->count( $orders ) ) : ?> |
| 98 | <div class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-24"><?php esc_html_e( 'Order History', 'tutor' ); ?></div> |
| 99 | <div class="tutor-table-responsive"> |
| 100 | <table class="tutor-table"> |
| 101 | <thead> |
| 102 | <th width="8%"> |
| 103 | <?php esc_html_e( 'Order ID', 'tutor' ); ?> |
| 104 | </th> |
| 105 | <th width="30%"> |
| 106 | <?php esc_html_e( 'Course Name', 'tutor' ); ?> |
| 107 | </th> |
| 108 | <th> |
| 109 | <?php esc_html_e( 'Date', 'tutor' ); ?> |
| 110 | </th> |
| 111 | <th> |
| 112 | <?php esc_html_e( 'Price', 'tutor' ); ?> |
| 113 | </th> |
| 114 | <th> |
| 115 | <?php esc_html_e( 'Status', 'tutor' ); ?> |
| 116 | </th> |
| 117 | <?php if ( Ecommerce::MONETIZE_BY === $monetize_by ) : ?> |
| 118 | <th> |
| 119 | <?php esc_html_e( 'Payment Method', 'tutor' ); ?> |
| 120 | </th> |
| 121 | <?php endif; ?> |
| 122 | <th></th> |
| 123 | </thead> |
| 124 | <?php if ( Ecommerce::MONETIZE_BY === $monetize_by ) : ?> |
| 125 | <tbody> |
| 126 | <?php |
| 127 | if ( is_array( $orders ) && count( $orders ) ) : |
| 128 | ?> |
| 129 | <?php |
| 130 | foreach ( $orders as $order ) : |
| 131 | ?> |
| 132 | <tr> |
| 133 | <td> |
| 134 | <div class="tutor-fs-7"> |
| 135 | #<?php echo esc_html( $order->id ); ?> |
| 136 | </div> |
| 137 | </td> |
| 138 | <td> |
| 139 | <div class="tutor-fs-7"> |
| 140 | <?php |
| 141 | $items = ( new OrderModel() )->get_order_items_by_id( $order->id ); |
| 142 | foreach ( $items as $item ) { |
| 143 | $course_id = $item->id; |
| 144 | if ( OrderModel::TYPE_SUBSCRIPTION ) { |
| 145 | $course_id = apply_filters( 'tutor_subscription_course_by_plan', $item->id, $order ); |
| 146 | } |
| 147 | ?> |
| 148 | <li> |
| 149 | <?php echo esc_html( get_the_title( $course_id ) ); ?> |
| 150 | </li> |
| 151 | <?php |
| 152 | } |
| 153 | ?> |
| 154 | </div> |
| 155 | </td> |
| 156 | <td> |
| 157 | <div class="tutor-fs-7 tutor-text-nowrap"> |
| 158 | <?php echo esc_html( DateTimeHelper::get_gmt_to_user_timezone_date( $order->created_at_gmt ) ); ?> |
| 159 | </div> |
| 160 | </td> |
| 161 | <td> |
| 162 | <div class="tutor-fs-7"> |
| 163 | <?php echo esc_html( tutor_get_formatted_price( $order->total_price ) ); ?> |
| 164 | </div> |
| 165 | </td> |
| 166 | <td> |
| 167 | <?php |
| 168 | echo wp_kses_post( tutor_utils()->translate_dynamic_text( $order->order_status, true ) ); |
| 169 | ?> |
| 170 | </td> |
| 171 | <td> |
| 172 | <div class="tutor-fs-7"> |
| 173 | <?php echo esc_html( Ecommerce::get_payment_method_label( $order->payment_method ?? '' ) ); ?> |
| 174 | </div> |
| 175 | </td> |
| 176 | <td> |
| 177 | <div class="tutor-d-flex tutor-gap-1 tutor-justify-end"> |
| 178 | <?php if ( OrderModel::should_show_pay_btn( $order ) ) : ?> |
| 179 | <form method="post"> |
| 180 | <?php tutor_nonce_field(); ?> |
| 181 | <input type="hidden" name="tutor_action" value="tutor_pay_incomplete_order"> |
| 182 | <input type="hidden" name="order_id" value="<?php echo esc_attr( $order->id ); ?>"> |
| 183 | <button type="submit" class="tutor-btn tutor-btn-sm tutor-btn-outline-primary"> |
| 184 | <?php esc_html_e( 'Pay', 'tutor' ); ?> |
| 185 | </button> |
| 186 | </form> |
| 187 | <?php endif; ?> |
| 188 | <?php do_action( 'tutor_dashboard_invoice_button', $order ); ?> |
| 189 | </div> |
| 190 | </td> |
| 191 | </tr> |
| 192 | <?php endforeach; ?> |
| 193 | <?php else : ?> |
| 194 | <?php tutor_utils()->tutor_empty_state(); ?> |
| 195 | <?php endif; ?> |
| 196 | </tbody> |
| 197 | <?php else : ?> |
| 198 | <tbody> |
| 199 | <?php foreach ( $orders as $order ) : ?> |
| 200 | <?php |
| 201 | if ( 'wc' === $monetize_by ) { |
| 202 | $wc_order = wc_get_order( $order->ID ); |
| 203 | $price = tutor_utils()->tutor_price( $wc_order->get_total() ); |
| 204 | $raw_price = $wc_order->get_total(); |
| 205 | $status = $order->post_status; |
| 206 | $badge_class = 'primary'; |
| 207 | $order_status_text = ''; |
| 208 | |
| 209 | switch ( $status ) { |
| 210 | case 'wc-completed' === $status: |
| 211 | $badge_class = 'success'; |
| 212 | $order_status_text = __( 'Completed', 'tutor' ); |
| 213 | break; |
| 214 | case 'wc-processing' === $status: |
| 215 | $badge_class = 'warning'; |
| 216 | $order_status_text = __( 'Processing', 'tutor' ); |
| 217 | break; |
| 218 | case 'wc-on-hold' === $status: |
| 219 | $badge_class = 'warning'; |
| 220 | $order_status_text = __( 'On Hold', 'tutor' ); |
| 221 | break; |
| 222 | case 'wc-refunded' === $status: |
| 223 | $badge_class = 'danger'; |
| 224 | $order_status_text = __( 'Processing', 'tutor' ); |
| 225 | break; |
| 226 | case 'wc-cancelled' === $status: |
| 227 | $badge_class = 'danger'; |
| 228 | $order_status_text = __( 'Cancelled', 'tutor' ); |
| 229 | break; |
| 230 | case 'wc-pending' === $status: |
| 231 | $badge_class = 'warning'; |
| 232 | $order_status_text = __( 'Pending', 'tutor' ); |
| 233 | break; |
| 234 | } |
| 235 | } elseif ( 'edd' === $monetize_by ) { |
| 236 | $edd_order = edd_get_payment( $order->ID ); |
| 237 | $price = edd_currency_filter( edd_format_amount( $edd_order->total ), edd_get_payment_currency_code( $order->ID ) ); |
| 238 | $raw_price = $edd_order->total; |
| 239 | $status = $edd_order->status_nicename; |
| 240 | $badge_class = 'primary'; |
| 241 | $order_status_text = $status; |
| 242 | } |
| 243 | ?> |
| 244 | <tr> |
| 245 | <td> |
| 246 | #<?php echo esc_html( $order->ID ); ?> |
| 247 | </td> |
| 248 | |
| 249 | <td> |
| 250 | <?php |
| 251 | $courses = tutor_utils()->get_course_enrolled_ids_by_order_id( $order->ID ); |
| 252 | if ( tutor_utils()->count( $courses ) ) { |
| 253 | foreach ( $courses as $course ) { |
| 254 | echo '<div>' . esc_html( get_the_title( $course['course_id'] ) ) . '</div>'; |
| 255 | } |
| 256 | } |
| 257 | ?> |
| 258 | </td> |
| 259 | |
| 260 | <td> |
| 261 | <?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $order->post_date ) ) ); ?> |
| 262 | </td> |
| 263 | |
| 264 | <td> |
| 265 | <?php echo wp_kses_post( $price ); ?> |
| 266 | </td> |
| 267 | |
| 268 | <td> |
| 269 | <span class="tutor-badge-label label-<?php echo esc_attr( $badge_class ); ?> tutor-m-4"><?php echo esc_html( $order_status_text ); ?></span> |
| 270 | </td> |
| 271 | <td> |
| 272 | <?php |
| 273 | $pay_now_url = ''; |
| 274 | if ( 'wc' === $monetize_by ) { |
| 275 | $wc_order = wc_get_order( $order->ID ); |
| 276 | $pay_now_url = esc_url( $wc_order->get_checkout_payment_url() ); |
| 277 | } |
| 278 | ?> |
| 279 | <div class="tutor-order-history-actions"> |
| 280 | <?php if ( 'wc-pending' === $status ) : ?> |
| 281 | <a href="<?php echo esc_url( $pay_now_url ); ?>" |
| 282 | class="tutor-btn tutor-btn-outline-primary tutor-btn-sm tutor-mr-8"> |
| 283 | <?php esc_html_e( 'Pay', 'tutor-pro' ); ?> |
| 284 | </a> |
| 285 | <?php endif; ?> |
| 286 | <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 ); ?>"> |
| 287 | <span class="tutor-icon-receipt-line" area-hidden="true"></span> |
| 288 | </a> |
| 289 | </div> |
| 290 | </td> |
| 291 | </tr> |
| 292 | <?php endforeach; ?> |
| 293 | </tbody> |
| 294 | <?php endif; ?> |
| 295 | </table> |
| 296 | </div> |
| 297 | |
| 298 | <?php |
| 299 | $pagination_data = array( |
| 300 | 'total_items' => $total_orders, |
| 301 | 'per_page' => $per_page, |
| 302 | 'paged' => $paged, |
| 303 | ); |
| 304 | |
| 305 | $total_page = ceil( $pagination_data['total_items'] / $pagination_data['per_page'] ); |
| 306 | |
| 307 | if ( $total_page > 1 ) { |
| 308 | $pagination_template = tutor()->path . 'templates/dashboard/elements/pagination.php'; |
| 309 | tutor_load_template_from_custom_path( $pagination_template, $pagination_data ); |
| 310 | } |
| 311 | ?> |
| 312 | <?php else : ?> |
| 313 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 314 | <?php endif; ?> |
| 315 | </div> |
| 316 |