billing-form-fields.php
1 year ago
billing.php
1 year ago
cart.php
10 months ago
checkout-details.php
8 months ago
checkout.php
8 months ago
order-placement-failed.php
8 months ago
order-placement-success.php
8 months ago
checkout-details.php
229 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Checkout info template |
| 4 | * |
| 5 | * @package Tutor\Views |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 3.0.0 |
| 9 | */ |
| 10 | |
| 11 | use TUTOR\Input; |
| 12 | use Tutor\Ecommerce\Tax; |
| 13 | use Tutor\Models\OrderModel; |
| 14 | use Tutor\Ecommerce\Settings; |
| 15 | use Tutor\Models\CouponModel; |
| 16 | use Tutor\Ecommerce\CartController; |
| 17 | use Tutor\Ecommerce\CheckoutController; |
| 18 | |
| 19 | /** |
| 20 | * User ID is required. |
| 21 | * Renders this view only (excluding checkout.php) when the country or state changes via AJAX. |
| 22 | */ |
| 23 | $user_id = apply_filters( 'tutor_checkout_user_id', get_current_user_id() ); |
| 24 | |
| 25 | $coupon_model = new CouponModel(); |
| 26 | $cart_controller = new CartController( false ); |
| 27 | $checkout_controller = new CheckoutController( false ); |
| 28 | $order_id = (int) Input::sanitize_request_data( 'order_id', 0 ); |
| 29 | $order_data = $order_id ? OrderModel::get_valid_incomplete_order( $order_id, (int) $user_id, true ) : null; |
| 30 | $get_cart = ! empty( $order_data ) ? $checkout_controller->get_courses_data_by_order_items( $order_data->items ) : $cart_controller->get_cart_items(); |
| 31 | $courses = $get_cart['courses']; |
| 32 | $total_count = $courses['total_count']; |
| 33 | $course_id = (int) Input::sanitize_request_data( 'course_id', 0 ); |
| 34 | $course_list = Settings::is_buy_now_enabled() && $course_id ? array( get_post( $course_id ) ) : $courses['results']; |
| 35 | $coupon_code = Input::sanitize_request_data( 'coupon_code', '' ); |
| 36 | |
| 37 | $plan_id = (int) Input::sanitize_request_data( 'plan' ); |
| 38 | $plan_info = apply_filters( 'tutor_get_plan_info', null, $plan_id ); |
| 39 | $has_plan_info = $plan_id && $plan_info; |
| 40 | |
| 41 | // Contains Course/Bundle/Plan ids. |
| 42 | $object_ids = array(); |
| 43 | $item_ids = $has_plan_info ? array( $plan_info->id ) : array_column( $course_list, 'ID' ); |
| 44 | $order_type = $has_plan_info ? OrderModel::TYPE_SUBSCRIPTION : OrderModel::TYPE_SINGLE_ORDER; |
| 45 | |
| 46 | // Check for applicable coupon in the existing order data. |
| 47 | $has_applicable_coupon = ! empty( $order_data ) && empty( $coupon_code ) && $coupon_model->order_has_applicable_coupon( $order_data ); |
| 48 | $coupon_code = $has_applicable_coupon ? $order_data->coupon_code : apply_filters( 'tutor_checkout_coupon_code', $coupon_code, $order_type, $item_ids ); |
| 49 | $has_manual_coupon_code = ! empty( $coupon_code ); |
| 50 | |
| 51 | $should_calculate_tax = Tax::should_calculate_tax(); |
| 52 | $is_tax_included_in_price = Tax::is_tax_included_in_price(); |
| 53 | $tax_rate = Tax::get_user_tax_rate( $user_id ); |
| 54 | |
| 55 | $checkout_data = $checkout_controller->prepare_checkout_items( $item_ids, $order_type, $coupon_code ); |
| 56 | $show_coupon_box = Settings::is_coupon_usage_enabled() && ! $checkout_data->is_coupon_applied; |
| 57 | ?> |
| 58 | |
| 59 | <div class="tutor-checkout-details"> |
| 60 | |
| 61 | <?php do_action( 'tutor_before_checkout_order_details', $course_list ); ?> |
| 62 | |
| 63 | <div class="tutor-checkout-details-inner"> |
| 64 | <h5 class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-border-bottom tutor-pb-8"> |
| 65 | <?php esc_html_e( 'Order Details', 'tutor' ); ?> |
| 66 | </h5> |
| 67 | <div class="tutor-checkout-detail-item"> |
| 68 | <div class="tutor-checkout-courses"> |
| 69 | <?php |
| 70 | // Subscription plan checkout item. |
| 71 | if ( $plan_info ) { |
| 72 | $plan_item_template = apply_filters( 'tutor_checkout_plan_item_template', null, $plan_info ); |
| 73 | if ( file_exists( $plan_item_template ) ) { |
| 74 | require $plan_item_template; |
| 75 | } |
| 76 | } else { |
| 77 | /** |
| 78 | * Course and bundle checkout items. |
| 79 | */ |
| 80 | if ( is_array( $course_list ) && count( $course_list ) ) : |
| 81 | ?> |
| 82 | <?php |
| 83 | foreach ( $checkout_data->items as $item ) : |
| 84 | $course = get_post( $item->item_id ); |
| 85 | $course_thumbnail = get_tutor_course_thumbnail_src( 'post-thumbnail', $course->ID ); |
| 86 | array_push( $object_ids, $item->item_id ); |
| 87 | ?> |
| 88 | <div class="tutor-checkout-course-item" data-course-id="<?php echo esc_attr( $item->item_id ); ?>"> |
| 89 | <div class="tutor-d-flex tutor-align-center tutor-gap-4px"> |
| 90 | <?php do_action( 'tutor_cart_item_badge', $course ); ?> |
| 91 | </div> |
| 92 | <div class="tutor-checkout-course-content"> |
| 93 | <div class="tutor-d-flex tutor-flex-column tutor-gap-1"> |
| 94 | <div class="tutor-checkout-course-thumb-title"> |
| 95 | <img src="<?php echo esc_url( $course_thumbnail ); ?>" alt="<?php echo esc_attr( $course->post_title ); ?>" /> |
| 96 | <h6 class="tutor-checkout-course-title"> |
| 97 | <a href="<?php echo esc_url( get_the_permalink( $course ) ); ?>"> |
| 98 | <?php echo esc_html( $course->post_title ); ?> |
| 99 | </a> |
| 100 | </h6> |
| 101 | </div> |
| 102 | <div class="tutor-checkout-coupon-badge <?php echo esc_attr( $item->is_coupon_applied ? '' : 'tutor-d-none' ); ?>"> |
| 103 | <i class="tutor-icon-tag" area-hidden="true"></i> |
| 104 | <span><?php echo esc_html( $item->is_coupon_applied ? $checkout_data->coupon_title : '' ); ?></span> |
| 105 | </div> |
| 106 | </div> |
| 107 | <div class="tutor-text-right"> |
| 108 | <div class="tutor-fw-bold"> |
| 109 | <?php tutor_print_formatted_price( $item->display_price ); ?> |
| 110 | </div> |
| 111 | <?php if ( $item->sale_price || $item->discount_price ) : ?> |
| 112 | <div class="tutor-checkout-discount-price"> |
| 113 | <?php tutor_print_formatted_price( $item->regular_price ); ?> |
| 114 | </div> |
| 115 | <?php endif; ?> |
| 116 | <?php if ( $checkout_data->total_items > 1 && $item->tax_amount > 0 && $item->tax_collection ) : ?> |
| 117 | <div class="tutor-fs-8 tutor-color-muted tutor-checkout-incl-tax-label"> |
| 118 | <?php echo esc_html( $item->tax_amount_readable ); ?> |
| 119 | </div> |
| 120 | <?php endif; ?> |
| 121 | </div> |
| 122 | </div> |
| 123 | </div> |
| 124 | <?php endforeach; ?> |
| 125 | <?php else : ?> |
| 126 | <?php tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); ?> |
| 127 | <?php endif; ?> |
| 128 | <?php } ?> |
| 129 | </div> |
| 130 | </div> |
| 131 | |
| 132 | <div class="tutor-checkout-detail-item tutor-checkout-summary"> |
| 133 | <div class="tutor-checkout-summary-item"> |
| 134 | <div class="tutor-fw-medium"><?php esc_html_e( 'Subtotal', 'tutor' ); ?></div> |
| 135 | <div class="tutor-fw-bold"> |
| 136 | <?php tutor_print_formatted_price( $checkout_data->subtotal_price ); ?> |
| 137 | </div> |
| 138 | </div> |
| 139 | |
| 140 | <?php if ( $checkout_data->sale_discount > 0 ) : ?> |
| 141 | <div class="tutor-checkout-summary-item"> |
| 142 | <div> |
| 143 | <?php |
| 144 | $sale_discount_label = apply_filters( 'tutor_checkout_sale_discount_label', __( 'Sale discount', 'tutor' ) ); |
| 145 | echo esc_html( $sale_discount_label ); |
| 146 | ?> |
| 147 | </div> |
| 148 | <div class="tutor-fw-bold"> |
| 149 | - <?php tutor_print_formatted_price( $checkout_data->sale_discount ); ?> |
| 150 | </div> |
| 151 | </div> |
| 152 | <?php endif ?> |
| 153 | |
| 154 | <?php if ( $show_coupon_box ) : ?> |
| 155 | <div class="tutor-checkout-summary-item tutor-have-a-coupon"> |
| 156 | <div><?php esc_html_e( 'Have a coupon?', 'tutor' ); ?></div> |
| 157 | <button type="button" id="tutor-toggle-coupon-button" class="tutor-btn tutor-btn-link"> |
| 158 | <?php esc_html_e( 'Click here', 'tutor' ); ?> |
| 159 | </button> |
| 160 | </div> |
| 161 | <div class="tutor-apply-coupon-form tutor-d-none"> |
| 162 | <input type="text" name="coupon_code" |
| 163 | <?php if ( 'manual' === $checkout_data->coupon_type && $checkout_data->is_coupon_applied ) : ?> |
| 164 | value="<?php echo esc_attr( $coupon_code ); ?>" |
| 165 | <?php endif; ?> |
| 166 | placeholder="<?php esc_html_e( 'Add coupon code', 'tutor' ); ?>"> |
| 167 | <button type="button" id="tutor-apply-coupon-button" class="tutor-btn tutor-btn-secondary" data-object-ids="<?php echo esc_attr( implode( ',', $object_ids ) ); ?>"><?php esc_html_e( 'Apply', 'tutor' ); ?></button> |
| 168 | </div> |
| 169 | <?php endif; ?> |
| 170 | |
| 171 | <div class="tutor-checkout-summary-item tutor-checkout-coupon-wrapper <?php echo esc_attr( $checkout_data->is_coupon_applied ? '' : 'tutor-d-none' ); ?>"> |
| 172 | <div class="tutor-checkout-coupon-badge tutor-has-delete-button"> |
| 173 | <i class="tutor-icon-tag" area-hidden="true"></i> |
| 174 | <span><?php echo esc_html( $checkout_data->coupon_title ); ?></span> |
| 175 | |
| 176 | <?php if ( $checkout_data->is_coupon_applied ) : ?> |
| 177 | <button type="button" id="tutor-checkout-remove-coupon" class="tutor-btn"> |
| 178 | <i class="tutor-icon-times" area-hidden="true"></i> |
| 179 | </button> |
| 180 | <?php endif; ?> |
| 181 | </div> |
| 182 | <div class="tutor-fw-bold tutor-discount-amount">-<?php tutor_print_formatted_price( $checkout_data->coupon_discount ); ?></div> |
| 183 | </div> |
| 184 | |
| 185 | <?php if ( $checkout_data->tax_amount > 0 && ! $is_tax_included_in_price ) : ?> |
| 186 | <div class="tutor-checkout-summary-item tutor-checkout-tax-amount"> |
| 187 | <div><?php esc_html_e( 'Tax', 'tutor' ); ?></div> |
| 188 | <div class="tutor-fw-bold"><?php tutor_print_formatted_price( $checkout_data->tax_amount ); ?></div> |
| 189 | </div> |
| 190 | <?php endif; ?> |
| 191 | </div> |
| 192 | |
| 193 | <div class="tutor-pt-12 tutor-pb-20"> |
| 194 | <div class="tutor-checkout-summary-item"> |
| 195 | <div class="tutor-fw-medium"><?php esc_html_e( 'Grand Total', 'tutor' ); ?></div> |
| 196 | <div class="tutor-fs-5 tutor-fw-bold tutor-checkout-grand-total"> |
| 197 | <?php tutor_print_formatted_price( $checkout_data->total_price ); ?> |
| 198 | </div> |
| 199 | </div> |
| 200 | <div class="tutor-checkout-summary-item tutor-checkout-incl-tax-label"> |
| 201 | <div></div> |
| 202 | <?php if ( $checkout_data->tax_amount > 0 && $is_tax_included_in_price ) : ?> |
| 203 | <div class="tutor-fs-7 tutor-color-muted"> |
| 204 | <?php |
| 205 | /* translators: %s: tax amount */ |
| 206 | echo esc_html( sprintf( __( '(Incl. Tax %s)', 'tutor' ), tutor_get_formatted_price( $checkout_data->tax_amount ) ) ); |
| 207 | ?> |
| 208 | </div> |
| 209 | <?php endif ?> |
| 210 | </div> |
| 211 | |
| 212 | <input type="hidden" name="coupon_code" value="<?php echo esc_attr( $coupon_code ); ?>"> |
| 213 | <input type="hidden" name="object_ids" value="<?php echo esc_attr( implode( ',', $object_ids ) ); ?>"> |
| 214 | <input type="hidden" name="order_type" value="<?php echo esc_attr( $order_type ); ?>"> |
| 215 | </div> |
| 216 | |
| 217 | <?php |
| 218 | $is_zero_price = empty( $checkout_data->total_price ) && OrderModel::TYPE_SINGLE_ORDER === $checkout_data->order_type; |
| 219 | $pay_now_btn_text = $is_zero_price ? __( 'Enroll Now', 'tutor' ) : __( 'Pay Now', 'tutor' ); |
| 220 | $pay_now_btn_text = apply_filters( 'tutor_checkout_pay_now_btn_text', $pay_now_btn_text, $checkout_data ); |
| 221 | $show_payment_methods = apply_filters( 'tutor_checkout_show_payment_methods', ! $is_zero_price, $checkout_data ); |
| 222 | |
| 223 | $checkout_data->pay_now_btn_text = $pay_now_btn_text; |
| 224 | $checkout_data->payment_method_required = $show_payment_methods; |
| 225 | ?> |
| 226 | <input type="hidden" id="checkout_data" value="<?php echo esc_attr( wp_json_encode( $checkout_data ) ); ?>"> |
| 227 | </div> |
| 228 | </div> |
| 229 |