1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX Sensei Course Class |
4
|
|
|
* |
5
|
|
|
* @package lsx |
6
|
|
|
* @subpackage sensei |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
|
|
|
10
|
|
|
exit; // Exit if accessed directly. |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* LSX Sensei Course Class |
15
|
|
|
*/ |
16
|
|
|
class LSX_Sensei_Course { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Instance of class. |
20
|
|
|
* |
21
|
|
|
* @var self |
22
|
|
|
*/ |
23
|
|
|
private static $instance; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor. |
27
|
|
|
*/ |
28
|
|
|
public function __construct() { |
|
|
|
|
29
|
|
|
add_action( 'init', array( $this, 'init' ) ); |
30
|
|
|
} // End __construct() |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Fetches an instance of the class. |
34
|
|
|
* |
35
|
|
|
* @return self |
36
|
|
|
*/ |
37
|
|
|
public static function instance() { |
38
|
|
|
if ( ! self::$instance ) { |
|
|
|
|
39
|
|
|
self::$instance = new self(); |
40
|
|
|
} |
|
|
|
|
41
|
|
|
return self::$instance; |
42
|
|
|
} |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Run our changes. |
46
|
|
|
*/ |
47
|
|
|
public function init() { |
48
|
|
|
global $sensei; |
49
|
|
|
global $woothemes_sensei; |
50
|
|
|
|
51
|
|
|
// Switching the course filters and the headers around. |
52
|
|
|
remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 ); |
|
|
|
|
53
|
|
|
remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_sorting' ) ); |
54
|
|
|
remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_filters' ) ); |
55
|
|
|
add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 11, 0 ); |
56
|
|
|
add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_sorting' ), 12 ); |
57
|
|
|
add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_filters' ), 12 ); |
58
|
|
|
|
59
|
|
|
// First add the thumbnail. |
60
|
|
|
add_action( 'sensei_course_content_inside_before', array( $this, 'get_course_thumbnail' ), 1 ); |
61
|
|
|
|
62
|
|
|
// This is for our wrapper, we run it on 2, after the thumbnail we added. |
63
|
|
|
add_action( 'sensei_course_content_inside_before', array( $this, 'course_body_div_open' ), 1 ); |
64
|
|
|
add_action( 'sensei_course_content_inside_after', array( $this, 'course_body_div_close' ), 50 ); |
65
|
|
|
|
66
|
|
|
// This is for our wrapper, we run it on 2, after the thumbnail we added. |
67
|
|
|
add_action( 'sensei_course_content_inside_before', array( $this, 'course_body_div_results_open' ), 20 ); |
68
|
|
|
add_action( 'sensei_course_content_inside_after', array( $this, 'course_body_div_results_close' ), 49 ); |
69
|
|
|
|
70
|
|
|
add_action( 'sensei_single_course_content_inside_before', array( $this, 'display_course_amount' ), 20 ); |
71
|
|
|
|
72
|
|
|
// removes the course image above the content. |
73
|
|
|
remove_action( 'sensei_course_content_inside_before', array( $woothemes_sensei->course, 'course_image' ), 30, 1 ); |
74
|
|
|
// add the course image to the left of the content. |
75
|
|
|
add_action( 'lsx_sensei_course_content_inside_before', array( $woothemes_sensei->course, 'course_image' ), 30, 1 ); |
76
|
|
|
|
77
|
|
|
add_filter( 'attach_shortcode_hooks', 'lsx_attach_shortcode_hooks', 10, 1 ); |
78
|
|
|
|
79
|
|
|
} |
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Gets the current courses thumbnail for content-course.php |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function get_course_thumbnail() { |
87
|
|
|
?> |
88
|
|
|
<div class="course-thumbnail"> |
89
|
|
|
<?php do_action( 'lsx_sensei_course_content_inside_before', get_the_ID() ); ?> |
90
|
|
|
</div> |
91
|
|
|
<?php |
92
|
|
|
} |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* <div class="course-body"> for content-course.php |
96
|
|
|
* |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
|
|
public function course_body_div_open() { |
100
|
|
|
global $post, $current_user; |
101
|
|
|
$is_user_taking_course = Sensei_Utils::has_started_course( $post->ID, $current_user->ID ); |
|
|
|
|
102
|
|
|
$user_taking_course_class = ''; |
103
|
|
|
if ( ! empty( $is_user_taking_course ) ) { |
|
|
|
|
104
|
|
|
$user_taking_course_class = 'currently-in-course'; |
105
|
|
|
} |
106
|
|
|
?> |
107
|
|
|
<div class="course-body <?php echo esc_html( $user_taking_course_class ); ?>"> |
108
|
|
|
<?php |
109
|
|
|
} |
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* The closing </div> for <div class="course-body"> content-course.php |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function course_body_div_close() { |
117
|
|
|
?> |
118
|
|
|
</div> |
119
|
|
|
<?php |
120
|
|
|
} |
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* <div class="course-details-info"> for content-course.php, just for the info after the meta |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function course_body_div_results_open() { |
128
|
|
|
?> |
129
|
|
|
<div class="course-details-info"> |
130
|
|
|
<?php |
131
|
|
|
} |
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* The closing </div> for <div class="course-details-info"> content-course.php, just for the info after the meta |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function course_body_div_results_close() { |
139
|
|
|
?> |
140
|
|
|
</div> |
141
|
|
|
<?php |
142
|
|
|
} |
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Display the course price on a single course. |
146
|
|
|
* |
147
|
|
|
* @return void |
148
|
|
|
*/ |
149
|
|
|
public function display_course_amount() { |
150
|
|
|
global $post, $current_user; |
151
|
|
|
$is_user_taking_course = Sensei_Course::is_user_enrolled( $post->ID, $current_user->ID ); |
|
|
|
|
152
|
|
|
$is_user_starting_course = Sensei_Utils::has_started_course( $post->ID, $current_user->ID ); |
153
|
|
|
$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
154
|
|
|
$course_purchasable = ''; |
155
|
|
|
if ( class_exists( 'Sensei_WC' ) ) { |
|
|
|
|
156
|
|
|
$course_purchasable = Sensei_WC::is_course_purchasable( $post->ID ); |
|
|
|
|
157
|
|
|
$currency = get_woocommerce_currency_symbol(); |
|
|
|
|
158
|
|
|
$product = new WC_Product( $wc_post_id ); |
|
|
|
|
159
|
|
|
if ( ( ! empty( $product->get_price() ) ) && ( ( ! $is_user_taking_course ) || ( ! $is_user_starting_course ) ) ) { |
|
|
|
|
160
|
|
|
echo '<span class="course-product-price price"><span>' . esc_html( $currency ) . ' </span>' . sprintf( '%0.2f', esc_html( $product->get_price() ) ) . '</span>'; |
161
|
|
|
} elseif ( ( '' === $product->get_price() || 0 == $product->get_price() ) && $course_purchasable && ( ( ! $is_user_taking_course ) || ( ! $is_user_starting_course ) ) ) { |
|
|
|
|
162
|
|
|
echo '<span class="course-product-price price">' . wp_kses_post( 'Free!', 'lsx' ) . '</span>'; |
|
|
|
|
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} |
|
|
|
|
166
|
|
|
|
167
|
|
|
} // End Class |
168
|
|
|
new LSX_Sensei_Course(); |
169
|
|
|
|