billing-form-fields.php
1 year ago
billing.php
1 year ago
cart.php
10 months ago
checkout-details.php
2 months ago
checkout.php
8 months ago
order-placement-failed.php
8 months ago
order-placement-success.php
8 months ago
checkout.php
223 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Checkout 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 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | use Tutor\Ecommerce\CheckoutController; |
| 16 | use Tutor\Ecommerce\CartController; |
| 17 | use TUTOR\Input; |
| 18 | |
| 19 | $user_id = apply_filters( 'tutor_checkout_user_id', get_current_user_id() ); |
| 20 | |
| 21 | $tutor_toc_page_link = tutor_utils()->get_toc_page_link(); |
| 22 | $tutor_privacy_page_link = tutor_utils()->get_privacy_page_link(); |
| 23 | |
| 24 | $cart_controller = new CartController(); |
| 25 | $get_cart = $cart_controller->get_cart_items(); |
| 26 | $courses = $get_cart['courses']; |
| 27 | $total_count = $courses['total_count']; |
| 28 | $course_list = $courses['results']; |
| 29 | $subtotal = 0; |
| 30 | $course_ids = implode( ', ', array_values( array_column( $course_list, 'ID' ) ) ); |
| 31 | $plan_id = Input::get( 'plan', 0, Input::TYPE_INT ); |
| 32 | |
| 33 | $is_checkout_page = true; |
| 34 | |
| 35 | ?> |
| 36 | <div class="tutor-checkout-page"> |
| 37 | <div class="tutor-container"> |
| 38 | <div class="tutor-checkout-container"> |
| 39 | <?php |
| 40 | $echo_before_return = true; |
| 41 | $user_has_subscription = apply_filters( 'tutor_checkout_user_has_subscription', false, $plan_id, $echo_before_return ); |
| 42 | if ( $user_has_subscription ) { |
| 43 | return; |
| 44 | } |
| 45 | ?> |
| 46 | |
| 47 | <!-- Alert if nonce failed --> |
| 48 | <?php |
| 49 | $nonce_alert = get_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . 'pay_now_nonce_alert' ); |
| 50 | if ( $nonce_alert ) { |
| 51 | ?> |
| 52 | <div class="tutor-alert tutor-danger"> |
| 53 | <div class="tutor-color-danger"><?php echo esc_html( $nonce_alert[0] ); ?></div> |
| 54 | </div> |
| 55 | <?php |
| 56 | delete_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . 'pay_now_nonce_alert' ); |
| 57 | } |
| 58 | ?> |
| 59 | |
| 60 | <form method="post" id="tutor-checkout-form"> |
| 61 | <?php tutor_nonce_field(); ?> |
| 62 | <input type="hidden" name="tutor_action" value="tutor_pay_now"> |
| 63 | <div class="tutor-row tutor-g-5"> |
| 64 | <div class="tutor-col-md-6" tutor-checkout-details> |
| 65 | <?php |
| 66 | $file = __DIR__ . '/checkout-details.php'; |
| 67 | if ( file_exists( $file ) ) { |
| 68 | include $file; |
| 69 | } |
| 70 | ?> |
| 71 | </div> |
| 72 | <div class="tutor-col-md-6"> |
| 73 | <div class="tutor-checkout-billing"> |
| 74 | <div class="tutor-checkout-billing-inner"> |
| 75 | <?php |
| 76 | if ( ! is_user_logged_in() ) { |
| 77 | $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null ) ? '' : wp_login_url( tutor()->current_url ); |
| 78 | ?> |
| 79 | <div class="tutor-mb-32 tutor-d-flex tutor-align-center tutor-justify-between tutor-border tutor-radius-6 tutor-p-12"> |
| 80 | <p class="tutor-m-0"><?php esc_html_e( 'Already have an account?', 'tutor' ); ?></p> |
| 81 | <button type="button" class="tutor-btn tutor-btn-secondary tutor-btn-sm tutor-open-login-modal" data-login_url="<?php echo esc_url( $login_url ); ?>"> |
| 82 | <?php esc_html_e( 'Login', 'tutor' ); ?> |
| 83 | </button> |
| 84 | </div> |
| 85 | <?php } ?> |
| 86 | |
| 87 | <h5 class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-12 tutor-mt-0"> |
| 88 | <?php |
| 89 | $address_title = __( 'Billing Address', 'tutor' ); |
| 90 | if ( ! is_user_logged_in() ) { |
| 91 | $address_title = __( 'Continue as Guest', 'tutor' ); |
| 92 | } |
| 93 | |
| 94 | echo esc_html( $address_title ); |
| 95 | ?> |
| 96 | </h5> |
| 97 | |
| 98 | <div class="tutor-billing-fields"> |
| 99 | <?php require tutor()->path . 'templates/ecommerce/billing-form-fields.php'; ?> |
| 100 | </div> |
| 101 | <div class="tutor-payment-method-wrapper tutor-mt-20 <?php echo esc_attr( $show_payment_methods ? '' : 'tutor-d-none' ); ?>"> |
| 102 | <h5 class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-12"> |
| 103 | <?php esc_html_e( 'Payment Method', 'tutor' ); ?> |
| 104 | </h5> |
| 105 | <div class="tutor-checkout-payment-options tutor-mb-24"> |
| 106 | <input type="hidden" name="payment_type"> |
| 107 | |
| 108 | <?php if ( ! $show_payment_methods ) : ?> |
| 109 | <input type="hidden" name="payment_method" value="free" id="tutor-temp-payment-method"> |
| 110 | <?php endif; ?> |
| 111 | |
| 112 | <?php |
| 113 | $supported_gateways = $plan_id ? tutor_get_subscription_supported_payment_gateways() : tutor_get_all_active_payment_gateways(); |
| 114 | if ( empty( $supported_gateways ) ) { |
| 115 | ?> |
| 116 | |
| 117 | <div class="tutor-alert tutor-warning"> |
| 118 | <?php esc_html_e( 'No payment method found. Please contact the site administrator.', 'tutor' ); ?> |
| 119 | </div> |
| 120 | <?php |
| 121 | } else { |
| 122 | foreach ( $supported_gateways as $gateway ) { |
| 123 | list( 'name' => $name, 'label' => $label, 'icon' => $icon ) = $gateway; |
| 124 | $is_manual = $gateway['is_manual'] ?? false; |
| 125 | if ( $is_manual ) { |
| 126 | ?> |
| 127 | <label class="tutor-checkout-payment-item" data-payment-method="<?php echo esc_attr( $name ); ?>" data-payment-type="manual"> |
| 128 | <input type="radio" value="<?php echo esc_attr( $name ); ?>" name="payment_method" class="tutor-form-check-input"> |
| 129 | <div class="tutor-payment-item-content"> |
| 130 | <?php if ( ! empty( $icon ) ) : ?> |
| 131 | <img src ="<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $name ); ?>"/> |
| 132 | <?php endif; ?> |
| 133 | <?php echo esc_html( $label ); ?> |
| 134 | </div> |
| 135 | <div class="tutor-d-none tutor-payment-item-instructions"><?php echo wp_kses_post( $gateway['payment_instructions'] ?? '' ); ?></div> |
| 136 | </label> |
| 137 | <?php |
| 138 | } else { |
| 139 | ?> |
| 140 | <label class="tutor-checkout-payment-item" data-payment-type="automate"> |
| 141 | <input type="radio" name="payment_method" value="<?php echo esc_attr( $name ); ?>" class="tutor-form-check-input"> |
| 142 | <div class="tutor-payment-item-content"> |
| 143 | <?php if ( ! empty( $icon ) ) : ?> |
| 144 | <img src = "<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $name ); ?>"/> |
| 145 | <?php endif; ?> |
| 146 | <?php echo esc_html( $label ); ?> |
| 147 | </div> |
| 148 | </label> |
| 149 | <?php |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | ?> |
| 154 | </div> |
| 155 | |
| 156 | <div class="tutor-payment-instructions tutor-mb-20 tutor-d-none"></div> |
| 157 | </div> |
| 158 | <?php if ( null !== $tutor_toc_page_link ) : ?> |
| 159 | <div class="tutor-mt-20"> |
| 160 | <div class="tutor-form-check tutor-d-flex"> |
| 161 | <input type="checkbox" id="tutor_checkout_agree_to_terms" name="agree_to_terms" class="tutor-form-check-input" required> |
| 162 | <label for="tutor_checkout_agree_to_terms"> |
| 163 | <span class="tutor-color-subdued tutor-fw-normal"> |
| 164 | <?php esc_html_e( 'I agree with the website\'s', 'tutor' ); ?> |
| 165 | <a target="_blank" href="<?php echo esc_url( $tutor_toc_page_link ); ?>" class="tutor-color-primary"><?php esc_html_e( 'Terms of Use', 'tutor' ); ?></a> |
| 166 | <?php if ( null !== $tutor_privacy_page_link ) : ?> |
| 167 | <?php esc_html_e( 'and', 'tutor' ); ?> |
| 168 | <a target="_blank" href="<?php echo esc_url( $tutor_privacy_page_link ); ?>" class="tutor-color-primary"><?php esc_html_e( 'Privacy Policy', 'tutor' ); ?></a> |
| 169 | <?php endif; ?> |
| 170 | </span> |
| 171 | </label> |
| 172 | </div> |
| 173 | </div> |
| 174 | <?php endif; ?> |
| 175 | <!-- handle errors --> |
| 176 | <?php |
| 177 | $pay_now_errors = get_transient( CheckoutController::PAY_NOW_ERROR_TRANSIENT_KEY . $user_id ); |
| 178 | $pay_now_alert_msg = get_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . $user_id ); |
| 179 | |
| 180 | delete_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . $user_id ); |
| 181 | delete_transient( CheckoutController::PAY_NOW_ERROR_TRANSIENT_KEY . $user_id ); |
| 182 | if ( $pay_now_errors || $pay_now_alert_msg ) : |
| 183 | ?> |
| 184 | <div class="tutor-break-word tutor-mt-16"> |
| 185 | <?php |
| 186 | if ( ! empty( $pay_now_alert_msg ) ) : |
| 187 | list( $alert, $message ) = array_values( $pay_now_alert_msg ); |
| 188 | ?> |
| 189 | <div class="tutor-alert tutor-<?php echo esc_attr( $alert ); ?>"> |
| 190 | <div class="tutor-color-<?php echo esc_attr( $alert ); ?>"><?php echo esc_html( $message ); ?></div> |
| 191 | </div> |
| 192 | <?php endif; ?> |
| 193 | |
| 194 | <?php if ( is_array( $pay_now_errors ) && count( $pay_now_errors ) ) : ?> |
| 195 | <div class="tutor-alert tutor-danger"> |
| 196 | <ul class="tutor-mb-0"> |
| 197 | <?php foreach ( $pay_now_errors as $pay_now_err ) : ?> |
| 198 | <li class="tutor-color-danger"><?php echo esc_html( ucfirst( str_replace( '_', ' ', $pay_now_err ) ) ); ?></li> |
| 199 | <?php endforeach; ?> |
| 200 | </ul> |
| 201 | </div> |
| 202 | <?php endif; ?> |
| 203 | </div> |
| 204 | <?php endif; ?> |
| 205 | <!-- handle errors end --> |
| 206 | <?php $enable_pay_now_btn = apply_filters( 'tutor_checkout_enable_pay_now_btn', true, $checkout_data ); ?> |
| 207 | <button type="submit" <?php echo $enable_pay_now_btn ? '' : 'disabled'; ?> id="tutor-checkout-pay-now-button" class="tutor-btn tutor-btn-primary tutor-btn-lg tutor-w-100 tutor-justify-center tutor-mt-16"> |
| 208 | <?php echo esc_html( $pay_now_btn_text ); ?> |
| 209 | </button> |
| 210 | </div> |
| 211 | </div> |
| 212 | </div> |
| 213 | </div> |
| 214 | </form> |
| 215 | </div> |
| 216 | </div> |
| 217 | </div> |
| 218 | <?php |
| 219 | if ( ! is_user_logged_in() ) { |
| 220 | tutor_load_template_from_custom_path( tutor()->path . '/views/modal/login.php' ); |
| 221 | } |
| 222 | ?> |
| 223 |