| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for displaying order detail. |
| 4 |
* |
| 5 |
* This template can be overridden by copying it to yourtheme/learnpress/checkout/order-received.php. |
| 6 |
* |
| 7 |
* @author ThimPress |
| 8 |
* @package Learnpress/Templates |
| 9 |
* @version 4.0.4 |
| 10 |
*/ |
| 11 |
|
| 12 |
use LearnPress\Models\CourseModel; |
| 13 |
use LearnPress\Models\UserItems\UserCourseModel; |
| 14 |
use LearnPress\Models\UserModel; |
| 15 |
use LearnPress\TemplateHooks\Course\SingleCourseTemplate; |
| 16 |
use LearnPress\TemplateHooks\UserItem\UserCourseTemplate; |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit(); |
| 19 |
|
| 20 |
$user_id = get_current_user_id(); |
| 21 |
$lp_profile = learn_press_get_profile( $user_id ); |
| 22 |
$userModel = UserModel::find( $user_id, true ); |
| 23 |
?> |
| 24 |
<div class="lp-content-area"> |
| 25 |
<?php |
| 26 |
/** |
| 27 |
* @var LP_Order $order_received |
| 28 |
*/ |
| 29 |
if ( ! isset( $order_received ) ) { |
| 30 |
echo wp_sprintf( |
| 31 |
'<p>%s</p>', |
| 32 |
esc_html( |
| 33 |
apply_filters( |
| 34 |
'learn-press/order/received-invalid-order-message', |
| 35 |
__( 'Invalid order.', 'learnpress' ) |
| 36 |
) |
| 37 |
) |
| 38 |
); |
| 39 |
|
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
echo wp_sprintf( |
| 44 |
'<p>%s</p><p>%s</p>', |
| 45 |
esc_html( |
| 46 |
apply_filters( |
| 47 |
'learn-press/order/received-order-message', |
| 48 |
__( 'Thank you. Your order has been received.', 'learnpress' ) |
| 49 |
) |
| 50 |
), |
| 51 |
sprintf( |
| 52 |
__( 'Go to %1$s to continue browsing or go to %2$s', 'learnpress' ), |
| 53 |
sprintf( |
| 54 |
'<a href="%s">%s</a>', |
| 55 |
esc_url( learn_press_get_page_link( 'courses' ) ), |
| 56 |
esc_html__( 'Courses', 'learnpress' ) |
| 57 |
), |
| 58 |
sprintf( |
| 59 |
'<a href="%s">%s</a>', |
| 60 |
esc_url( $lp_profile->get_tab_link( 'orders' ) ), |
| 61 |
esc_html__( 'My Orders', 'learnpress' ) |
| 62 |
) |
| 63 |
) |
| 64 |
); |
| 65 |
do_action( 'learn-press/order/after-received-order-message', $order_received->get_id() ); |
| 66 |
|
| 67 |
?> |
| 68 |
<table class="order_details"> |
| 69 |
<?php if ( isset( $_GET['key'] ) && ! is_user_logged_in() ) : ?> |
| 70 |
<tr class="order-key"> |
| 71 |
<th><?php esc_html_e( 'Order Key', 'learnpress' ); ?></th> |
| 72 |
<td> |
| 73 |
<?php echo esc_html( $_GET['key'] ); ?> |
| 74 |
</td> |
| 75 |
</tr> |
| 76 |
<?php endif; ?> |
| 77 |
<tr class="order"> |
| 78 |
<th><?php esc_html_e( 'Order Number', 'learnpress' ); ?></th> |
| 79 |
<td> |
| 80 |
<?php echo esc_html( $order_received->get_order_number() ); ?> |
| 81 |
</td> |
| 82 |
</tr> |
| 83 |
<tr class="status"> |
| 84 |
<th><?php esc_html_e( 'Status', 'learnpress' ); ?></th> |
| 85 |
<td> |
| 86 |
<?php |
| 87 |
$status = $order_received->get_status(); |
| 88 |
echo ucfirst( $order_received::get_status_label( $status ) ); |
| 89 |
?> |
| 90 |
</td> |
| 91 |
</tr> |
| 92 |
<tr class="item"> |
| 93 |
<th><?php esc_html_e( 'Item', 'learnpress' ); ?></th> |
| 94 |
<td> |
| 95 |
<?php |
| 96 |
$links = array(); |
| 97 |
$items = $order_received->get_items(); |
| 98 |
$count = count( $items ); |
| 99 |
|
| 100 |
foreach ( $items as $item ) { |
| 101 |
if ( empty( $item['course_id'] ) || get_post_type( $item['course_id'] ) !== LP_COURSE_CPT ) { |
| 102 |
$links[] = apply_filters( |
| 103 |
'learn-press/order-item-not-course-id', |
| 104 |
__( 'The course does not exist', 'learnpress' ), |
| 105 |
$item |
| 106 |
); |
| 107 |
} else { |
| 108 |
$course_id = $item['course_id']; |
| 109 |
$courseModel = CourseModel::find( $course_id, true ); |
| 110 |
$button_course = ''; |
| 111 |
$userCourseModel = UserCourseModel::find( $user_id, $course_id, true ); |
| 112 |
if ( $userCourseModel && $userModel ) { |
| 113 |
// For enrolled or purchased course. |
| 114 |
$userCourseTemplate = UserCourseTemplate::instance(); |
| 115 |
$singleCourseTemplate = SingleCourseTemplate::instance(); |
| 116 |
|
| 117 |
// Load js button course. |
| 118 |
wp_enqueue_script( 'lp-single-course' ); |
| 119 |
|
| 120 |
if ( $userCourseModel->has_enrolled() ) { |
| 121 |
$button_course = $userCourseTemplate->html_btn_continue( $userCourseModel ); |
| 122 |
} elseif ( $userCourseModel->has_purchased() ) { |
| 123 |
$button_course = $singleCourseTemplate->html_btn_enroll_course( $courseModel, $userModel ); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
$link = sprintf( |
| 128 |
'<a href="%s">%s (#%s)</a> %s', |
| 129 |
get_the_permalink( $item['course_id'] ), |
| 130 |
get_the_title( $item['course_id'] ), |
| 131 |
$item['course_id'], |
| 132 |
$button_course |
| 133 |
); |
| 134 |
|
| 135 |
if ( $count > 1 ) { |
| 136 |
$link = sprintf( '<li>%s</li>', $link ); |
| 137 |
} |
| 138 |
$links[] = apply_filters( 'learn-press/order-received-item-link', $link, $item ); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if ( $count > 1 ) { |
| 143 |
echo sprintf( '<ol>%s</ol>', join( '', $links ) ); |
| 144 |
} elseif ( 1 == $count ) { |
| 145 |
echo implode( '', $links ); |
| 146 |
} else { |
| 147 |
echo esc_html__( '(No item)', 'learnpress' ); |
| 148 |
} |
| 149 |
?> |
| 150 |
</td> |
| 151 |
</tr> |
| 152 |
<tr class="date"> |
| 153 |
<th><?php esc_html_e( 'Date', 'learnpress' ); ?></th> |
| 154 |
<td> |
| 155 |
<?php |
| 156 |
echo wp_kses_post( |
| 157 |
date_i18n( |
| 158 |
get_option( 'date_format' ), |
| 159 |
strtotime( $order_received->get_order_date() ) |
| 160 |
) |
| 161 |
); |
| 162 |
?> |
| 163 |
</td> |
| 164 |
</tr> |
| 165 |
<tr class="total"> |
| 166 |
<th><?php esc_html_e( 'Total', 'learnpress' ); ?></th> |
| 167 |
<td> |
| 168 |
<?php echo wp_kses_post( $order_received->get_formatted_order_total() ); ?> |
| 169 |
</td> |
| 170 |
</tr> |
| 171 |
<?php |
| 172 |
$method_title = $order_received->get_payment_method_title(); |
| 173 |
if ( $method_title ) : |
| 174 |
?> |
| 175 |
<tr class="method"> |
| 176 |
<th><?php esc_html_e( 'Payment Method', 'learnpress' ); ?></th> |
| 177 |
<td> |
| 178 |
<?php echo esc_html( $method_title ); ?> |
| 179 |
</td> |
| 180 |
</tr> |
| 181 |
<?php endif; ?> |
| 182 |
<?php do_action( 'learn-press/order/received/items-table', $order_received ); ?> |
| 183 |
</table> |
| 184 |
|
| 185 |
<?php do_action( 'learn-press/order/received', $order_received ); ?> |
| 186 |
</div> |
| 187 |
|