add-to-cart-edd.php
5 days ago
add-to-cart-tutor.php
1 year ago
add-to-cart-woocommerce.php
1 year ago
course-author.php
3 years ago
course-continue.php
2 years ago
course-in-cart.php
1 year ago
course-price-edd.php
5 days ago
course-price-tutor.php
2 months ago
course-price-woocommerce.php
2 months ago
course-price.php
2 months ago
course.php
1 year ago
end_content_wrap.php
3 years ago
enrolled-course-progress.php
2 months ago
footer.php
1 year ago
header.php
9 months ago
loop-after-content.php
3 years ago
loop-before-content.php
3 years ago
loop-end.php
3 years ago
loop-start.php
3 years ago
meta.php
2 months ago
rating.php
3 years ago
start_content_wrap.php
3 years ago
thumbnail.php
3 years ago
title.php
3 years ago
add-to-cart-woocommerce.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * A single course loop add to cart |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage WooCommerceIntegration |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 1.4.3 |
| 10 | */ |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | $course_id = get_the_ID(); |
| 17 | $product_id = tutor_utils()->get_course_product_id(); |
| 18 | $product = wc_get_product( $product_id ); |
| 19 | |
| 20 | if ( ! $product_id || ! $product ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Add required logged-in class |
| 26 | * |
| 27 | * @since 1.5.5 |
| 28 | */ |
| 29 | $is_logged_in = is_user_logged_in(); |
| 30 | $enable_guest_course_cart = tutor_utils()->get_option( 'enable_guest_course_cart' ); |
| 31 | $required_loggedin_class = ''; |
| 32 | $ajax_add_to_cart_class = ''; |
| 33 | if ( ! $is_logged_in && ! $enable_guest_course_cart ) { |
| 34 | $required_loggedin_class = apply_filters( 'tutor_enroll_required_login_class', 'tutor-open-login-modal' ); |
| 35 | } else { |
| 36 | $ajax_add_to_cart_class = $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : ''; |
| 37 | } |
| 38 | |
| 39 | $args = array(); |
| 40 | $defaults = array( |
| 41 | 'quantity' => 1, |
| 42 | 'class' => implode( |
| 43 | ' ', |
| 44 | array_filter( |
| 45 | array( |
| 46 | 'tutor-btn tutor-btn-outline-primary tutor-btn-md tutor-btn-block ', |
| 47 | 'product_type_' . $product->get_type(), |
| 48 | $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button ' : '', |
| 49 | $ajax_add_to_cart_class, |
| 50 | $required_loggedin_class, |
| 51 | ) |
| 52 | ) |
| 53 | ), |
| 54 | 'attributes' => array( |
| 55 | 'data-product_id' => $product->get_id(), |
| 56 | 'data-product_sku' => $product->get_sku(), |
| 57 | 'aria-label' => $product->add_to_cart_description(), |
| 58 | 'rel' => 'nofollow', |
| 59 | ), |
| 60 | ); |
| 61 | |
| 62 | $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product ); |
| 63 | |
| 64 | if ( isset( $args['attributes']['aria-label'] ) ) { |
| 65 | $args['attributes']['aria-label'] = strip_tags( $args['attributes']['aria-label'] ); |
| 66 | } |
| 67 | |
| 68 | ?> |
| 69 | |
| 70 | <?php |
| 71 | //phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped --contain safe content |
| 72 | echo apply_filters( |
| 73 | 'tutor_course_restrict_new_entry', |
| 74 | apply_filters( |
| 75 | 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok. |
| 76 | sprintf( |
| 77 | '<a href="%s" data-quantity="%s" class="%s" %s><span class="tutor-icon-cart-line tutor-mr-8"></span><span class="cart-text">%s</span></a>', |
| 78 | esc_url( $product->add_to_cart_url() ), |
| 79 | esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ), |
| 80 | esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ), |
| 81 | isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', |
| 82 | esc_html( $product->add_to_cart_text() ) |
| 83 | ), |
| 84 | $product, |
| 85 | $args |
| 86 | ), |
| 87 | $course_id |
| 88 | ); |
| 89 | |
| 90 |