billing-form-fields.php
1 year ago
billing.php
1 year ago
cart.php
1 year ago
checkout-details.php
1 year ago
checkout.php
1 year ago
order-placement-failed.php
1 year ago
order-placement-success.php
1 year ago
checkout.php
209 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 | <form method="post" id="tutor-checkout-form"> |
| 48 | <?php tutor_nonce_field(); ?> |
| 49 | <input type="hidden" name="tutor_action" value="tutor_pay_now"> |
| 50 | <div class="tutor-row tutor-g-5"> |
| 51 | <div class="tutor-col-md-6" tutor-checkout-details> |
| 52 | <?php |
| 53 | $file = __DIR__ . '/checkout-details.php'; |
| 54 | if ( file_exists( $file ) ) { |
| 55 | include $file; |
| 56 | } |
| 57 | ?> |
| 58 | </div> |
| 59 | <div class="tutor-col-md-6"> |
| 60 | <div class="tutor-checkout-billing"> |
| 61 | <div class="tutor-checkout-billing-inner"> |
| 62 | <?php |
| 63 | if ( ! is_user_logged_in() ) { |
| 64 | $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null ) ? '' : wp_login_url( tutor()->current_url ); |
| 65 | ?> |
| 66 | <div class="tutor-mb-32 tutor-d-flex tutor-align-center tutor-justify-between tutor-border tutor-radius-6 tutor-p-12"> |
| 67 | <p class="tutor-mb-0"><?php esc_html_e( 'Already have an account?', 'tutor' ); ?></p> |
| 68 | <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 ); ?>"> |
| 69 | <?php esc_html_e( 'Login', 'tutor' ); ?> |
| 70 | </button> |
| 71 | </div> |
| 72 | <?php } ?> |
| 73 | |
| 74 | <h5 class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-12"> |
| 75 | <?php |
| 76 | $address_title = __( 'Billing Address', 'tutor' ); |
| 77 | if ( ! is_user_logged_in() ) { |
| 78 | $address_title = __( 'Continue as Guest', 'tutor' ); |
| 79 | } |
| 80 | |
| 81 | echo esc_html( $address_title ); |
| 82 | ?> |
| 83 | </h5> |
| 84 | |
| 85 | <div class="tutor-billing-fields"> |
| 86 | <?php require tutor()->path . 'templates/ecommerce/billing-form-fields.php'; ?> |
| 87 | </div> |
| 88 | <div class="tutor-payment-method-wrapper tutor-mt-20 <?php echo esc_attr( $show_payment_methods ? '' : 'tutor-d-none' ); ?>"> |
| 89 | <h5 class="tutor-fs-5 tutor-fw-medium tutor-color-black tutor-mb-12"> |
| 90 | <?php esc_html_e( 'Payment Method', 'tutor' ); ?> |
| 91 | </h5> |
| 92 | <div class="tutor-checkout-payment-options tutor-mb-24"> |
| 93 | <input type="hidden" name="payment_type"> |
| 94 | |
| 95 | <?php if ( ! $show_payment_methods ) : ?> |
| 96 | <input type="hidden" name="payment_method" value="free" id="tutor-temp-payment-method"> |
| 97 | <?php endif; ?> |
| 98 | |
| 99 | <?php |
| 100 | $supported_gateways = $plan_id ? tutor_get_subscription_supported_payment_gateways() : tutor_get_all_active_payment_gateways(); |
| 101 | if ( empty( $supported_gateways ) ) { |
| 102 | ?> |
| 103 | |
| 104 | <div class="tutor-alert tutor-warning"> |
| 105 | <?php esc_html_e( 'No payment method found. Please contact the site administrator.', 'tutor' ); ?> |
| 106 | </div> |
| 107 | <?php |
| 108 | } else { |
| 109 | foreach ( $supported_gateways as $gateway ) { |
| 110 | list( 'name' => $name, 'label' => $label, 'icon' => $icon ) = $gateway; |
| 111 | $is_manual = $gateway['is_manual'] ?? false; |
| 112 | if ( $is_manual ) { |
| 113 | ?> |
| 114 | <label class="tutor-checkout-payment-item" data-payment-method="<?php echo esc_attr( $name ); ?>" data-payment-type="manual" data-payment-details="<?php echo esc_attr( $gateway['additional_details'] ?? '' ); ?>" data-payment-instruction="<?php echo esc_attr( base64_encode( $gateway['payment_instructions'] ?? '' ) ); ?>"> |
| 115 | <input type="radio" value="<?php echo esc_attr( $name ); ?>" name="payment_method" class="tutor-form-check-input"> |
| 116 | <div class="tutor-payment-item-content"> |
| 117 | <?php if ( ! empty( $icon ) ) : ?> |
| 118 | <img src ="<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $name ); ?>"/> |
| 119 | <?php endif; ?> |
| 120 | <?php echo esc_html( $label ); ?> |
| 121 | </div> |
| 122 | </label> |
| 123 | <?php |
| 124 | } else { |
| 125 | ?> |
| 126 | <label class="tutor-checkout-payment-item" data-payment-type="automate"> |
| 127 | <input type="radio" name="payment_method" value="<?php echo esc_attr( $name ); ?>" class="tutor-form-check-input"> |
| 128 | <div class="tutor-payment-item-content"> |
| 129 | <?php if ( ! empty( $icon ) ) : ?> |
| 130 | <img src = "<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $name ); ?>"/> |
| 131 | <?php endif; ?> |
| 132 | <?php echo esc_html( $label ); ?> |
| 133 | </div> |
| 134 | </label> |
| 135 | <?php |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | ?> |
| 140 | </div> |
| 141 | |
| 142 | <div class="tutor-payment-instructions tutor-mb-20 tutor-d-none"></div> |
| 143 | </div> |
| 144 | <?php if ( null !== $tutor_toc_page_link ) : ?> |
| 145 | <div class="tutor-mt-20"> |
| 146 | <div class="tutor-form-check tutor-d-flex"> |
| 147 | <input type="checkbox" id="tutor_checkout_agree_to_terms" name="agree_to_terms" class="tutor-form-check-input" required> |
| 148 | <label for="tutor_checkout_agree_to_terms"> |
| 149 | <span class="tutor-color-subdued tutor-fw-normal"> |
| 150 | <?php esc_html_e( 'I agree with the website\'s', 'tutor' ); ?> |
| 151 | <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> |
| 152 | <?php if ( null !== $tutor_privacy_page_link ) : ?> |
| 153 | <?php esc_html_e( 'and', 'tutor' ); ?> |
| 154 | <a target="_blank" href="<?php echo esc_url( $tutor_privacy_page_link ); ?>" class="tutor-color-primary"><?php esc_html_e( 'Privacy Policy', 'tutor' ); ?></a> |
| 155 | <?php endif; ?> |
| 156 | </span> |
| 157 | </label> |
| 158 | </div> |
| 159 | </div> |
| 160 | <?php endif; ?> |
| 161 | <!-- handle errors --> |
| 162 | <?php |
| 163 | $pay_now_errors = get_transient( CheckoutController::PAY_NOW_ERROR_TRANSIENT_KEY . $user_id ); |
| 164 | $pay_now_alert_msg = get_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . $user_id ); |
| 165 | |
| 166 | delete_transient( CheckoutController::PAY_NOW_ALERT_MSG_TRANSIENT_KEY . $user_id ); |
| 167 | delete_transient( CheckoutController::PAY_NOW_ERROR_TRANSIENT_KEY . $user_id ); |
| 168 | if ( $pay_now_errors || $pay_now_alert_msg ) : |
| 169 | ?> |
| 170 | <div class="tutor-break-word tutor-mt-16"> |
| 171 | <?php |
| 172 | if ( ! empty( $pay_now_alert_msg ) ) : |
| 173 | list( $alert, $message ) = array_values( $pay_now_alert_msg ); |
| 174 | ?> |
| 175 | <div class="tutor-alert tutor-<?php echo esc_attr( $alert ); ?>"> |
| 176 | <div class="tutor-color-<?php echo esc_attr( $alert ); ?>"><?php echo esc_html( $message ); ?></div> |
| 177 | </div> |
| 178 | <?php endif; ?> |
| 179 | |
| 180 | <?php if ( is_array( $pay_now_errors ) && count( $pay_now_errors ) ) : ?> |
| 181 | <div class="tutor-alert tutor-danger"> |
| 182 | <ul class="tutor-mb-0"> |
| 183 | <?php foreach ( $pay_now_errors as $pay_now_err ) : ?> |
| 184 | <li class="tutor-color-danger"><?php echo esc_html( ucfirst( str_replace( '_', ' ', $pay_now_err ) ) ); ?></li> |
| 185 | <?php endforeach; ?> |
| 186 | </ul> |
| 187 | </div> |
| 188 | <?php endif; ?> |
| 189 | </div> |
| 190 | <?php endif; ?> |
| 191 | <!-- handle errors end --> |
| 192 | <?php $enable_pay_now_btn = apply_filters( 'tutor_checkout_enable_pay_now_btn', true, $checkout_data ); ?> |
| 193 | <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"> |
| 194 | <?php echo esc_html( $pay_now_btn_text ); ?> |
| 195 | </button> |
| 196 | </div> |
| 197 | </div> |
| 198 | </div> |
| 199 | </div> |
| 200 | </form> |
| 201 | </div> |
| 202 | </div> |
| 203 | </div> |
| 204 | <?php |
| 205 | if ( ! is_user_logged_in() ) { |
| 206 | tutor_load_template_from_custom_path( tutor()->path . '/views/modal/login.php' ); |
| 207 | } |
| 208 | ?> |
| 209 |