Completed
Push — master ( eccc4a...c847f3 )
by Dwain
04:57
created
includes/hooks/template.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
  *
19 19
  ***************************/
20 20
 //This hook allow us to change the template WordPress loads for a given page/post_type @since 1.9.0
21
-add_filter( 'template_include', array ( 'Sensei_Templates', 'template_loader' ), 10, 1 );
21
+add_filter('template_include', array('Sensei_Templates', 'template_loader'), 10, 1);
22 22
 
23 23
 //This hook adds the sensei pagination to the pagination hook
24
-add_action( 'sensei_pagination', array( 'Sensei_Frontend', 'load_content_pagination' ), 30 );
24
+add_action('sensei_pagination', array('Sensei_Frontend', 'load_content_pagination'), 30);
25 25
 
26 26
 
27 27
 /***************************
@@ -32,16 +32,16 @@  discard block
 block discarded – undo
32 32
  *
33 33
  ***************************/
34 34
 // deprecate the archive content hook @since 1.9.0
35
-add_action( 'sensei_archive_before_course_loop', array ( 'Sensei_Templates', 'deprecated_archive_course_content_hook' ), 10, 1 );
35
+add_action('sensei_archive_before_course_loop', array('Sensei_Templates', 'deprecated_archive_course_content_hook'), 10, 1);
36 36
 
37 37
 // Course archive title hook @since 1.9.0
38
-add_action('sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 );
38
+add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'archive_header'), 10, 0);
39 39
 
40 40
 // add the course image above the content
41
-add_action('sensei_course_content_inside_before', array( Sensei()->course, 'course_image' ) ,10, 1 );
41
+add_action('sensei_course_content_inside_before', array(Sensei()->course, 'course_image'), 10, 1);
42 42
 
43 43
 // add course content title to the courses on the archive page
44
-add_action('sensei_course_content_inside_before', array( 'Sensei_Templates', 'the_title' ) ,5, 1 );
44
+add_action('sensei_course_content_inside_before', array('Sensei_Templates', 'the_title'), 5, 1);
45 45
 
46 46
 /***************************
47 47
  *
@@ -53,33 +53,33 @@  discard block
 block discarded – undo
53 53
 // @1.9.0
54 54
 // add deprecated action hooks for backwards compatibility sake
55 55
 // hooks on single course page: sensei_course_image , sensei_course_single_title, sensei_course_single_meta
56
-add_action('sensei_single_course_content_inside_before', array( 'Sensei_Templates', 'deprecated_single_course_inside_before_hooks' ), 80);
56
+add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecated_single_course_inside_before_hooks'), 80);
57 57
 
58 58
 // @1.9.0
59 59
 // hook the single course title on the single course page
60
-add_action( 'sensei_single_course_content_inside_before',array( 'Sensei_Course', 'the_title'), 10 );
60
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_title'), 10);
61 61
 
62 62
 // @1.9.0
63 63
 // hook the single course title on the single course page
64
-add_action( 'sensei_single_course_content_inside_before', array( Sensei()->course , 'course_image'), 20 );
64
+add_action('sensei_single_course_content_inside_before', array(Sensei()->course, 'course_image'), 20);
65 65
 
66 66
 
67 67
 // @1.9.0
68 68
 //Add legacy hooks deprecated in 1.9.0
69
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Templates','deprecate_course_single_meta_hooks'), 10 );
69
+add_action('sensei_single_course_content_inside_before', array('Sensei_Templates', 'deprecate_course_single_meta_hooks'), 10);
70 70
 
71 71
 // @1.9.0
72 72
 // Filter the content and replace it with the excerpt if the user doesn't have full access
73
-add_filter( 'the_content', array( 'Sensei_Course', 'single_course_content' ) );
73
+add_filter('the_content', array('Sensei_Course', 'single_course_content'));
74 74
 
75 75
 // @1.9.0
76 76
 // Deprecate lessons specific single course hooks
77
-add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_course_single_lessons_hook' ) );
77
+add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_course_single_lessons_hook'));
78 78
 
79 79
 // @1.9.0
80 80
 // Deprecate single main content hooks
81
-add_action( 'sensei_single_course_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') );
82
-add_action( 'sensei_single_message_content_inside_after', array( 'Sensei_Templates', 'deprecated_single_main_content_hook') );
81
+add_action('sensei_single_course_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook'));
82
+add_action('sensei_single_message_content_inside_after', array('Sensei_Templates', 'deprecated_single_main_content_hook'));
83 83
 
84 84
 /**
85 85
  * Deprecate all the post type single titile hooks in favor of before content and after content hooks
@@ -87,74 +87,74 @@  discard block
 block discarded – undo
87 87
  * @deprecate 1.9.0
88 88
  * @1.9.0
89 89
  */
90
-add_action('sensei_single_message_content_inside_before', array( 'Sensei_Templates', 'deprecate_all_post_type_single_title_hooks' ) );
90
+add_action('sensei_single_message_content_inside_before', array('Sensei_Templates', 'deprecate_all_post_type_single_title_hooks'));
91 91
 
92 92
 /**
93 93
  * Deprecate hooks into the single course modules
94 94
  * @deprecated since 1.9.0
95 95
  */
96
-add_action('sensei_single_course_modules_before', array('Sensei_Templates','deprecate_module_before_hook' ) );
97
-add_action('sensei_single_course_modules_after', array('Sensei_Templates','deprecate_module_after_hook' ) );
96
+add_action('sensei_single_course_modules_before', array('Sensei_Templates', 'deprecate_module_before_hook'));
97
+add_action('sensei_single_course_modules_after', array('Sensei_Templates', 'deprecate_module_after_hook'));
98 98
 
99 99
 // @since 1.9.0
100 100
 // add the single course lessons title
101
-add_action( 'sensei_single_course_content_inside_after' , array( 'Sensei_Course','the_course_lessons_title'), 9 );
101
+add_action('sensei_single_course_content_inside_after', array('Sensei_Course', 'the_course_lessons_title'), 9);
102 102
 
103 103
 // @since 1.9.0
104 104
 // hooks in the course lessons query and remove it at the end
105 105
 // also loading the course lessons template in the middle
106
-add_action( 'sensei_single_course_lessons_before', array('Sensei_Course','load_single_course_lessons_query' ) );
107
-add_action( 'sensei_single_course_content_inside_after', 'course_single_lessons', 10 );
108
-add_action( 'sensei_single_course_lessons_after', array( 'Sensei_Utils','restore_wp_query' ));
106
+add_action('sensei_single_course_lessons_before', array('Sensei_Course', 'load_single_course_lessons_query'));
107
+add_action('sensei_single_course_content_inside_after', 'course_single_lessons', 10);
108
+add_action('sensei_single_course_lessons_after', array('Sensei_Utils', 'restore_wp_query'));
109 109
 
110 110
 // @since 1.9.0
111 111
 // add post classes to the lessons on the single course page
112
-add_filter( 'post_class', array( 'Sensei_Lesson', 'single_course_lessons_classes' ) );
112
+add_filter('post_class', array('Sensei_Lesson', 'single_course_lessons_classes'));
113 113
 
114 114
 // @since 1.9.0
115 115
 // lesson meta information on the single course page
116
-add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_meta') , 5);
116
+add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_meta'), 5);
117 117
 
118 118
 //@since 1.9.0
119 119
 // lesson image
120
-add_action( 'sensei_single_course_inside_before_lesson', array('Sensei_Lesson','the_lesson_thumbnail') , 8);
120
+add_action('sensei_single_course_inside_before_lesson', array('Sensei_Lesson', 'the_lesson_thumbnail'), 8);
121 121
 
122 122
 //@since 1.9.0
123 123
 // lesson custom excerpts
124
-add_filter( 'get_the_excerpt', array( 'Sensei_Lesson', 'alter_the_lesson_excerpt' ) );
124
+add_filter('get_the_excerpt', array('Sensei_Lesson', 'alter_the_lesson_excerpt'));
125 125
 
126 126
 // @since 1.9.0
127 127
 // run a deprecated hook for backwards compatibility sake
128
-add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content'  ) );
128
+add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'deprecate_sensei_single_course_modules_content'));
129 129
 
130 130
 // @since 1.9.0
131 131
 // hook in the module loop intialization functionality
132
-add_action( 'sensei_single_course_modules_before', array( 'Sensei_Core_Modules', 'setup_single_course_module_loop' ) );
132
+add_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'setup_single_course_module_loop'));
133 133
 
134 134
 // @since 1.9.0
135 135
 // hook in the module loop destructor functionality
136
-add_action( 'sensei_single_course_modules_after', array( 'Sensei_Core_Modules', 'teardown_single_course_module_loop' ) );
136
+add_action('sensei_single_course_modules_after', array('Sensei_Core_Modules', 'teardown_single_course_module_loop'));
137 137
 
138 138
 // @since 1.9.0
139 139
 // hook in the possible full content override to show instead of excerpt
140
-add_filter('get_the_excerpt', array( 'Sensei_Course', 'full_content_excerpt_override' ) );
140
+add_filter('get_the_excerpt', array('Sensei_Course', 'full_content_excerpt_override'));
141 141
 
142 142
 //@since 1.9.0
143 143
 //Course meta
144
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course', 'the_course_enrolment_actions' ), 30 );
145
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_Course' , 'the_course_video' ), 40 );
144
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_enrolment_actions'), 30);
145
+add_action('sensei_single_course_content_inside_before', array('Sensei_Course', 'the_course_video'), 40);
146 146
 
147 147
 //
148 148
 //// no permissions template for the single course
149 149
 //
150
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_Course', 'the_title'), 20 );
151
-add_action( 'sensei_no_permissions_inside_before_content', array( Sensei()->course , 'course_image'), 25 );
152
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_Course' , 'the_course_video' ), 40 );
153
-add_action( 'sensei_no_permissions_inside_after_content', array( Sensei()->modules, 'load_course_module_content_template') , 43 );
154
-add_action( 'sensei_no_permissions_inside_after_content' , array( 'Sensei_Course','the_course_lessons_title'), 45 );
155
-add_action( 'sensei_no_permissions_inside_after_content', array('Sensei_Course','load_single_course_lessons_query' ),50 );
156
-add_action( 'sensei_no_permissions_inside_after_content', 'course_single_lessons', 60 );
157
-add_action( 'sensei_no_permissions_inside_after_content', array( 'Sensei_Utils','restore_wp_query' ), 70);
150
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_Course', 'the_title'), 20);
151
+add_action('sensei_no_permissions_inside_before_content', array(Sensei()->course, 'course_image'), 25);
152
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_Course', 'the_course_video'), 40);
153
+add_action('sensei_no_permissions_inside_after_content', array(Sensei()->modules, 'load_course_module_content_template'), 43);
154
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Course', 'the_course_lessons_title'), 45);
155
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Course', 'load_single_course_lessons_query'), 50);
156
+add_action('sensei_no_permissions_inside_after_content', 'course_single_lessons', 60);
157
+add_action('sensei_no_permissions_inside_after_content', array('Sensei_Utils', 'restore_wp_query'), 70);
158 158
 
159 159
 /***************************
160 160
  *
@@ -165,54 +165,54 @@  discard block
 block discarded – undo
165 165
  ***************************/
166 166
 //@since 1.9.0
167 167
 // deprecate hooks no longer needed
168
-add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook' ) );
169
-add_action( 'sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook' ) );
168
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_single_main_content_hook'));
169
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'deprecate_quiz_sensei_quiz_single_title_hook'));
170 170
 
171 171
 //@since 1.9.0
172 172
 // Single quiz title
173
-add_filter( 'the_title', array( 'Sensei_Quiz' , 'single_quiz_title' ), 20 , 2 ); // append Quiz
174
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_title' ), 20 ); //output single quiz
173
+add_filter('the_title', array('Sensei_Quiz', 'single_quiz_title'), 20, 2); // append Quiz
174
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_title'), 20); //output single quiz
175 175
 
176 176
 // since 1.9.0
177 177
 // initialize the quiz questions loop
178
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'start_quiz_questions_loop') );
178
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'start_quiz_questions_loop'));
179 179
 
180 180
 // since 1.9.0
181 181
 // hook in the quiz user message
182
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Quiz', 'the_user_status_message' ), 40 );
182
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Quiz', 'the_user_status_message'), 40);
183 183
 
184 184
 //@since 1.9.0
185 185
 // hook in the question title, description and quesiton media
186
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_title' ), 10 );
187
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_description' ), 20 );
188
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_media' ), 30 );
189
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question','the_question_hidden_fields' ), 40 );
186
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_title'), 10);
187
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_description'), 20);
188
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_media'), 30);
189
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_question_hidden_fields'), 40);
190 190
 
191 191
 //@since 1.9.0
192 192
 // hook in incorrect / correct message above questions if the quiz has been graded
193
-add_action( 'sensei_quiz_question_inside_before', array( 'Sensei_Question', 'the_answer_result_indication' ), 50 );
193
+add_action('sensei_quiz_question_inside_before', array('Sensei_Question', 'the_answer_result_indication'), 50);
194 194
 
195 195
 //@since 1.9.0
196 196
 // add answer grading feedback at the bottom of the question
197
-add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Question', 'answer_feedback_notes' ) );
197
+add_action('sensei_quiz_question_inside_after', array('Sensei_Question', 'answer_feedback_notes'));
198 198
 
199 199
 //@since 1.9.0
200 200
 // add extra question data for different quesiton types when get_question_template_data_is_called.
201
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','multiple_choice_load_question_data'), 10, 3);
202
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','gap_fill_load_question_data'), 10, 3);
203
-add_filter( 'sensei_get_question_template_data', array( 'Sensei_Question','file_upload_load_question_data'), 10, 3);
201
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'multiple_choice_load_question_data'), 10, 3);
202
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'gap_fill_load_question_data'), 10, 3);
203
+add_filter('sensei_get_question_template_data', array('Sensei_Question', 'file_upload_load_question_data'), 10, 3);
204 204
 
205 205
 //@since 1.9.0
206 206
 // deprecate the quiz button action
207
-add_action( 'sensei_single_quiz_questions_after', array( 'Sensei_Quiz', 'action_buttons' ), 10, 0 );
207
+add_action('sensei_single_quiz_questions_after', array('Sensei_Quiz', 'action_buttons'), 10, 0);
208 208
 
209 209
 //@since 1.9.0
210 210
 // deprecate the sensei_complete_quiz hook
211
-add_action( 'sensei_single_quiz_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_complete_quiz_action' ));
211
+add_action('sensei_single_quiz_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_complete_quiz_action'));
212 212
 
213 213
 //@since 1.9.0
214 214
 // deprecate the sensei_quiz_question_type hook
215
-add_action( 'sensei_quiz_question_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_quiz_question_type_action' ));
215
+add_action('sensei_quiz_question_inside_after', array('Sensei_Templates', 'deprecate_sensei_quiz_question_type_action'));
216 216
 
217 217
 /***************************
218 218
  *
@@ -223,63 +223,63 @@  discard block
 block discarded – undo
223 223
  ***************************/
224 224
 //@since 1.9.0
225 225
 // deprecate the main content hook on the single lesson page
226
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_lesson_single_main_content_hook' ), 20);
226
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_single_main_content_hook'), 20);
227 227
 
228 228
 //@since 1.9.0
229 229
 // hook in the lesson image on the single lesson
230
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'the_lesson_image' ), 17 );
230
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'the_lesson_image'), 17);
231 231
 
232 232
 //@since 1.9.0
233 233
 // hook in the lesson image on the single lesson deprecated hook function
234
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates','deprecate_lesson_image_hook' ), 10 );
234
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_lesson_image_hook'), 10);
235 235
 
236 236
 //@since 1.9.0
237 237
 // hook in the lesson single title deprecated function
238
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_title' ), 15 );
238
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_lesson_single_title'), 15);
239 239
 
240 240
 // @since 1.9.0
241 241
 // hook in the sensei lesson user notices
242
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_not_taking_course_message' ), 15 );
242
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_not_taking_course_message'), 15);
243 243
 
244 244
 // @since 1.9.0
245 245
 // attach the lesson title
246
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'the_title' ), 15 );
246
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'the_title'), 15);
247 247
 
248 248
 //@since 1.9.0
249 249
 // hook in the lesson image on the single lesson
250
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'user_lesson_quiz_status_message' ), 20 );
250
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'user_lesson_quiz_status_message'), 20);
251 251
 
252 252
 // @since 1.9.0
253 253
 // add the single lesson meta
254
-add_action( 'sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10 );
254
+add_action('sensei_single_lesson_content_inside_after', 'sensei_the_single_lesson_meta', 10);
255 255
 
256 256
 // @since 1.9.0
257 257
 // deprecate the sensei_lesson_single_meta hook
258
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook' ), 15 );
258
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_single_meta_hook'), 15);
259 259
 
260 260
 // @since 1.9.0
261 261
 // deprecate the sensei_lesson_course_signup hook
262
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Templates','deprecate_sensei_lesson_course_signup_hook' ), 20 );
262
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_lesson_course_signup_hook'), 20);
263 263
 
264 264
 // @since 1.9.0
265 265
 // hook in the lesson prerequisite completion message
266
-add_action( 'sensei_single_lesson_content_inside_after', array( 'Sensei_Lesson', 'prerequisite_complete_message' ), 20 );
266
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'prerequisite_complete_message'), 20);
267 267
 
268 268
 // @since 1.9.0
269 269
 // hook the single lesson course_signup_link
270
-add_action( 'sensei_single_lesson_content_inside_before', array( 'Sensei_Lesson', 'course_signup_link' ), 30 );
270
+add_action('sensei_single_lesson_content_inside_before', array('Sensei_Lesson', 'course_signup_link'), 30);
271 271
 
272 272
 // @since 1.9.0
273 273
 // hook the deprecate breadcrumbs and comments hooks
274
-add_action( 'sensei_after_main_content', array( 'Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5 );
274
+add_action('sensei_after_main_content', array('Sensei_Templates', 'deprecate_single_lesson_breadcrumbs_and_comments_hooks'), 5);
275 275
 
276 276
 // @since 1.9.0
277 277
 // Add the quiz specific buttons and notices to the lesson
278
-add_action( 'sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action' ));
278
+add_action('sensei_single_lesson_content_inside_after', array('Sensei_Lesson', 'footer_quiz_call_to_action'));
279 279
 
280 280
 // @since 1.9.0
281 281
 // hook in the comments on the single lessons page
282
-add_action( 'sensei_pagination', array( 'Sensei_Lesson', 'output_comments' ), 90 );
282
+add_action('sensei_pagination', array('Sensei_Lesson', 'output_comments'), 90);
283 283
 
284 284
 /**********************
285 285
  *
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
  *
290 290
  ************************/
291 291
 
292
-add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_title' ), 20 );
292
+add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_title'), 20);
293 293
 
294
-add_action( 'sensei_single_message_content_inside_before', array( 'Sensei_Messages', 'the_message_sent_by_title' ), 40 );
294
+add_action('sensei_single_message_content_inside_before', array('Sensei_Messages', 'the_message_sent_by_title'), 40);
295 295
 
296 296
 /*************************
297 297
  *
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 
304 304
 // deprecate the sensei_lesson_archive_header hook
305 305
 // @deprecated since 1.9.0
306
-add_action( 'sensei_loop_lesson_inside_before', array( 'Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook' ), 20 );
306
+add_action('sensei_loop_lesson_inside_before', array('Sensei_Lesson', 'deprecate_sensei_lesson_archive_header_hook'), 20);
307 307
 
308 308
 // @1.9.0
309 309
 //The archive title header on the lesson archive loop
310
-add_action( 'sensei_loop_lesson_inside_before', array( Sensei()->lesson, 'the_archive_header' ), 20 );
310
+add_action('sensei_loop_lesson_inside_before', array(Sensei()->lesson, 'the_archive_header'), 20);
311 311
 
312 312
 // @since 1.9.0
313 313
 //Output the lesson header on the content-lesson.php which runs inside the lessons loop
314
-add_action( 'sensei_content_lesson_inside_before', array( 'Sensei_Lesson', 'the_lesson_meta' ), 20 );
314
+add_action('sensei_content_lesson_inside_before', array('Sensei_Lesson', 'the_lesson_meta'), 20);
315 315
 
316 316
 // @since 1.9.0
317 317
 // output only part of the lesson on the archive
318
-add_filter('the_content', array( 'Sensei_Lesson','limit_archive_content' ) );
318
+add_filter('the_content', array('Sensei_Lesson', 'limit_archive_content'));
319 319
 
320 320
 /**************************
321 321
  *
@@ -326,15 +326,15 @@  discard block
 block discarded – undo
326 326
  **************************/
327 327
 // @since 1.9.0
328 328
 // deprecate the learner profile content hook as the markup code is added in the template directly.
329
-add_action('sensei_learner_profile_content_before', array( 'Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook' ) );
329
+add_action('sensei_learner_profile_content_before', array('Sensei_Learner_Profiles', 'deprecate_sensei_learner_profile_content_hook'));
330 330
 
331 331
 // @since 1.9.0
332 332
 // do the sensei complete course action on the learner profiles page.
333
-add_action('sensei_learner_profile_content_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) );
333
+add_action('sensei_learner_profile_content_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook'));
334 334
 
335 335
 // @since 1.9.0
336 336
 // fire the frontend messages hook before the profile content
337
-add_action('sensei_learner_profile_inside_content_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) );
337
+add_action('sensei_learner_profile_inside_content_before', array('Sensei_Templates', 'fire_frontend_messages_hook'));
338 338
 
339 339
 
340 340
 /**********************************
@@ -347,26 +347,26 @@  discard block
 block discarded – undo
347 347
 
348 348
 // @since 1.9.0
349 349
 // fire the deprecated hook function within the course-result.php file
350
-add_action( 'sensei_course_results_content_before', array('Sensei_Course_Results','deprecate_sensei_course_results_content_hook') );
350
+add_action('sensei_course_results_content_before', array('Sensei_Course_Results', 'deprecate_sensei_course_results_content_hook'));
351 351
 
352 352
 // @since 1.9.0
353 353
 // fire the sensei message hooke inside the course-result.php file
354
-add_action( 'sensei_course_results_content_inside_before', array('Sensei_Course_Results','fire_sensei_message_hook') );
354
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_sensei_message_hook'));
355 355
 
356 356
 // @since 1.9.0
357 357
 // load the course information on the course results page
358
-add_action( 'sensei_course_results_content_inside_before_lessons', array( Sensei()->course_results,'course_info') );
358
+add_action('sensei_course_results_content_inside_before_lessons', array(Sensei()->course_results, 'course_info'));
359 359
 
360 360
 // @since 1.9.0
361
-add_action( 'sensei_course_results_content_inside_before', array( Sensei()->course,'course_image') );
361
+add_action('sensei_course_results_content_inside_before', array(Sensei()->course, 'course_image'));
362 362
 
363 363
 // @since 1.9.0
364 364
 // deprecate the course results top hook in favour of a new hook
365
-add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'deprecate_course_results_top_hook') );
365
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'deprecate_course_results_top_hook'));
366 366
 
367 367
 // @since 1.9.0
368 368
 // Fire the course image hook within the course results page
369
-add_action( 'sensei_course_results_content_inside_before', array( 'Sensei_Course_Results', 'fire_course_image_hook') );
369
+add_action('sensei_course_results_content_inside_before', array('Sensei_Course_Results', 'fire_course_image_hook'));
370 370
 
371 371
 
372 372
 /**********************************
@@ -378,19 +378,19 @@  discard block
 block discarded – undo
378 378
  ********************************/
379 379
 // @since 1.9.0
380 380
 // fire the sensei complete course action on the my courses template
381
-add_action( 'sensei_my_courses_before', array( 'Sensei_Templates', 'fire_sensei_complete_course_hook' ) );
381
+add_action('sensei_my_courses_before', array('Sensei_Templates', 'fire_sensei_complete_course_hook'));
382 382
 
383 383
 // @since 1.9.0
384 384
 // fire the sensei frontend messages hook before the my-courses content
385
-add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'fire_frontend_messages_hook' ) );
385
+add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'fire_frontend_messages_hook'));
386 386
 
387 387
 // @since 1.9.0
388 388
 // deprecate the sensei_before_user_course_content hook
389
-add_action('sensei_my_courses_content_inside_before', array( 'Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook' ) );
389
+add_action('sensei_my_courses_content_inside_before', array('Sensei_Templates', 'deprecate_sensei_before_user_course_content_hook'));
390 390
 
391 391
 // @since 1.9.0
392 392
 // deprecate the sensei_after_user_course_content hook
393
-add_action('sensei_my_courses_content_inside_after', array( 'Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook' ) );
393
+add_action('sensei_my_courses_content_inside_after', array('Sensei_Templates', 'deprecate_sensei_after_user_course_content_hook'));
394 394
 
395 395
 /**********************************
396 396
  *
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 // @since 1.9.0
403 403
 // deprecate the sensei_login_form hok which was use to load the login form.
404 404
 // This now loads independent of the my-courses template which helps keep templates free from logic
405
-add_action( 'sensei_login_form_before', array( 'Sensei_Templates', 'deprecate_sensei_login_form_hook' ) );
405
+add_action('sensei_login_form_before', array('Sensei_Templates', 'deprecate_sensei_login_form_hook'));
406 406
 
407 407
 /**********************************
408 408
  *
@@ -413,16 +413,16 @@  discard block
 block discarded – undo
413 413
  ********************************/
414 414
 // @since 1.9.0
415 415
 // Deprecate the archive messages hooks no longer supported
416
-add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Templates', 'deprecated_archive_message_hooks' ) );
416
+add_action('sensei_archive_before_message_loop', array('Sensei_Templates', 'deprecated_archive_message_hooks'));
417 417
 
418 418
 // @since 1.9.0
419 419
 // Deprecate the archive messages hooks no longer supported
420
-add_action( 'sensei_archive_before_message_loop', array( 'Sensei_Messages', 'the_archive_header' ) );
420
+add_action('sensei_archive_before_message_loop', array('Sensei_Messages', 'the_archive_header'));
421 421
 
422 422
 // @since 1.9.0
423 423
 // output the message title and the message sensei
424
-add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_title' ), 10, 1 );
425
-add_action( 'sensei_content_message_before', array( 'Sensei_Messages', 'the_message_sender' ), 20 , 1 );
424
+add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_title'), 10, 1);
425
+add_action('sensei_content_message_before', array('Sensei_Messages', 'the_message_sender'), 20, 1);
426 426
 
427 427
 /**********************************
428 428
  *
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
  *
432 432
  *
433 433
  **********************************/
434
-add_action( 'sensei_loop_course_before', array( 'Sensei_Course', 'course_category_title' ), 70 , 1 );
434
+add_action('sensei_loop_course_before', array('Sensei_Course', 'course_category_title'), 70, 1);
435 435
 
436 436
 /**********************************
437 437
  *
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
  **********************************/
443 443
 //@since 1.9.0
444 444
 //add a title to the teacher archive page when viewn siteurl/author/{teacher-username}
445
-add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'archive_title' ) );
445
+add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'archive_title'));
446 446
 
447 447
 //@since 1.9.0
448 448
 // remove course meta from the teacher page until it can be refactored to allow only removing the
449 449
 // teacher name and not all lessons
450
-add_action( 'sensei_teacher_archive_course_loop_before', array( 'Sensei_Teacher', 'remove_course_meta_on_teacher_archive' ) );
450
+add_action('sensei_teacher_archive_course_loop_before', array('Sensei_Teacher', 'remove_course_meta_on_teacher_archive'));
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 4 patches
Doc Comments   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
      * @since   1.2.0
974 974
      * @since  1.9.0 move to class Sensei_WC
975 975
      *
976
-     * @param   WC_Order $order
976
+     * @param   integer $order
977 977
      *
978 978
      * @return  void
979 979
      */
@@ -1191,6 +1191,7 @@  discard block
 block discarded – undo
1191 1191
      * @since   1.2.0
1192 1192
      * @since   1.9.0 Move function to the Sensei_WC class
1193 1193
      * @param   integer| WC_Order $order_id order ID
1194
+     * @param integer $order_id
1194 1195
      * @return  void
1195 1196
      */
1196 1197
     public static function cancel_order ( $order_id ) {
@@ -1309,7 +1310,7 @@  discard block
 block discarded – undo
1309 1310
      * @param  int 			$course_id  (default: 0)
1310 1311
      * @param  array/Object $order_user (default: array()) Specific user's data.
1311 1312
      *
1312
-     * @return bool|int
1313
+     * @return boolean|string
1313 1314
      */
1314 1315
     public static function course_update ( $course_id = 0, $order_user = array()  ) {
1315 1316
 
@@ -1381,7 +1382,7 @@  discard block
 block discarded – undo
1381 1382
      *
1382 1383
      * @param  boolean $guest_checkout Current guest checkout setting
1383 1384
      *
1384
-     * @return boolean                 Modified guest checkout setting
1385
+     * @return string|boolean                 Modified guest checkout setting
1385 1386
      */
1386 1387
     public static function disable_guest_checkout( $guest_checkout ) {
1387 1388
 
@@ -1555,7 +1556,7 @@  discard block
 block discarded – undo
1555 1556
      * Get all the valid subscription types.
1556 1557
      *
1557 1558
      * @since 1.9.0
1558
-     * @return array
1559
+     * @return string[]
1559 1560
      */
1560 1561
     public static function get_subscription_types(){
1561 1562
 
@@ -1573,8 +1574,8 @@  discard block
 block discarded – undo
1573 1574
      *
1574 1575
      * @since 1.9.0
1575 1576
      *
1576
-     * @param $user_id
1577
-     * @param $product_id
1577
+     * @param integer $user_id
1578
+     * @param string $product_id
1578 1579
      * @param $course_id
1579 1580
      *
1580 1581
      * @return bool
@@ -1638,7 +1639,7 @@  discard block
 block discarded – undo
1638 1639
 	 * Get all the orders for a specific user and product combination
1639 1640
 	 *
1640 1641
 	 * @param int $user_id
1641
-	 * @param $product_id
1642
+	 * @param integer $product_id
1642 1643
 	 *
1643 1644
 	 * @return array $orders
1644 1645
 	 */
Please login to merge, or discard this patch.
Indentation   +1204 added lines, -1204 removed lines patch added patch discarded remove patch
@@ -12,745 +12,745 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 Class Sensei_WC{
15
-    /**
16
-     * Load the files needed for the woocommerce integration.
17
-     *
18
-     * @since 1.9.0
19
-     */
20
-    public static function load_woocommerce_integration_hooks(){
15
+	/**
16
+	 * Load the files needed for the woocommerce integration.
17
+	 *
18
+	 * @since 1.9.0
19
+	 */
20
+	public static function load_woocommerce_integration_hooks(){
21 21
 
22
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
-        require_once( $woocommerce_hooks_file_path );
22
+		$woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
+		require_once( $woocommerce_hooks_file_path );
24 24
 
25
-    }
26
-    /**
27
-     * check if WooCommerce plugin is loaded and allowed by Sensei
28
-     *
29
-     * @since 1.9.0
30
-     * @return bool
31
-     */
32
-    public static function is_woocommerce_active(){
25
+	}
26
+	/**
27
+	 * check if WooCommerce plugin is loaded and allowed by Sensei
28
+	 *
29
+	 * @since 1.9.0
30
+	 * @return bool
31
+	 */
32
+	public static function is_woocommerce_active(){
33 33
 
34
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
-        return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
34
+		$is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
+		return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
36 36
 
37
-    } // end is_woocommerce_active
37
+	} // end is_woocommerce_active
38 38
 
39
-    /**
40
-     * Checks if the WooCommerce plugin is installed and activation.
41
-     *
42
-     * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
43
-     * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
44
-     *
45
-     * @since 1.9.0
46
-     *
47
-     * @return bool
48
-     */
49
-    public static function is_woocommerce_present(){
39
+	/**
40
+	 * Checks if the WooCommerce plugin is installed and activation.
41
+	 *
42
+	 * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
43
+	 * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
44
+	 *
45
+	 * @since 1.9.0
46
+	 *
47
+	 * @return bool
48
+	 */
49
+	public static function is_woocommerce_present(){
50 50
 
51
-        $active_plugins = (array) get_option( 'active_plugins', array() );
51
+		$active_plugins = (array) get_option( 'active_plugins', array() );
52 52
 
53
-        if ( is_multisite() ){
53
+		if ( is_multisite() ){
54 54
 
55
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55
+			$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
56 56
 
57
-        }
57
+		}
58 58
 
59
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59
+		$is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
60 60
 
61
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61
+		return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
62 62
 
63
-    }// end is_woocommerce_present
63
+	}// end is_woocommerce_present
64 64
 
65
-    /**
66
-     * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
67
-     *
68
-     * If multiple exist we will return the latest order.
69
-     *
70
-     * @param $user_id
71
-     * @param $course_id
72
-     * @return array $user_course_orders
73
-     */
74
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
65
+	/**
66
+	 * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
67
+	 *
68
+	 * If multiple exist we will return the latest order.
69
+	 *
70
+	 * @param $user_id
71
+	 * @param $course_id
72
+	 * @return array $user_course_orders
73
+	 */
74
+	public static function get_learner_course_active_order_id( $user_id, $course_id ){
75 75
 
76
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76
+		$course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
77 77
 
78
-        $orders_query = new WP_Query( array(
79
-            'post_type'   => 'shop_order',
80
-            'posts_per_page' => -1,
81
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
82
-            'meta_key'=> '_customer_user',
83
-            'meta_value'=> $user_id,
84
-        ) );
78
+		$orders_query = new WP_Query( array(
79
+			'post_type'   => 'shop_order',
80
+			'posts_per_page' => -1,
81
+			'post_status' => array( 'wc-processing', 'wc-completed' ),
82
+			'meta_key'=> '_customer_user',
83
+			'meta_value'=> $user_id,
84
+		) );
85 85
 
86
-        if( $orders_query->post_count == 0 ){
86
+		if( $orders_query->post_count == 0 ){
87 87
 
88
-            return false;
88
+			return false;
89 89
 
90
-        }
90
+		}
91
+
92
+		foreach( $orders_query->get_posts() as $order ){
93
+
94
+			$order = new WC_Order( $order->ID );
95
+			$items = $order->get_items();
96
+
97
+			$user_orders =  array();
98
+
99
+			foreach( $items as $item ){
100
+
101
+				// if the product id on the order and the one given to this function
102
+				// this order has been placed by the given user on the given course.
103
+				$product = wc_get_product( $item['product_id'] );
104
+
105
+				if ( is_object( $product ) && $product->is_type( 'variable' )) {
106
+
107
+					$item_product_id = $item['variation_id'];
108
+
109
+				} else {
91 110
 
92
-        foreach( $orders_query->get_posts() as $order ){
111
+					$item_product_id =  $item['product_id'];
93 112
 
94
-            $order = new WC_Order( $order->ID );
95
-            $items = $order->get_items();
113
+				}
96 114
 
97
-            $user_orders =  array();
115
+				if( $course_product_id == $item_product_id ){
98 116
 
99
-            foreach( $items as $item ){
117
+					return $order->id;
100 118
 
101
-                // if the product id on the order and the one given to this function
102
-                // this order has been placed by the given user on the given course.
103
-                $product = wc_get_product( $item['product_id'] );
119
+				}
104 120
 
105
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
106 121
 
107
-                    $item_product_id = $item['variation_id'];
122
+			}//end for each order item
108 123
 
109
-                } else {
124
+		} // end for each order
110 125
 
111
-                    $item_product_id =  $item['product_id'];
126
+		// if we reach this place we found no order
127
+		return false;
112 128
 
113
-                }
129
+	} // end get_learner_course_active_order_ids
130
+
131
+	/**
132
+	 * Output WooCommerce specific course filters
133
+	 * Removing the paged argument
134
+	 *
135
+	 * @since 1.9.0
136
+	 * @param $filter_links
137
+	 * @return mixed
138
+	 */
139
+	public static function add_course_archive_wc_filter_links( $filter_links ){
140
+
141
+		$free_courses = self::get_free_courses();
142
+		$paid_courses = self::get_paid_courses();
143
+
144
+		if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
+			// do not show any WooCommerce filters if all courses are
146
+			// free or if all courses are paid
147
+			return $filter_links;
148
+
149
+		}
114 150
 
115
-                if( $course_product_id == $item_product_id ){
151
+		$filter_links[] = array(
152
+			'id'=>'paid' ,
153
+			'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
+			'title'=>__( 'Paid', 'woothemes-sensei' )
155
+		);
116 156
 
117
-                    return $order->id;
157
+		$filter_links[] = array(
158
+			'id'=>'free',
159
+			'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
+			'title'=>__( 'Free', 'woothemes-sensei' )
161
+		);
118 162
 
119
-                }
163
+		return $filter_links;
120 164
 
165
+	}// end add_course_archive_wc_filter_links
121 166
 
122
-            }//end for each order item
167
+	/**
168
+	 * Apply the free filter the the course query
169
+	 * getting all course with no products or products with zero price
170
+	 *
171
+	 * hooked into pre_get_posts
172
+	 *
173
+	 * @since 1.9.0
174
+	 * @param WP_Query $query
175
+	 * @return WP_Query $query
176
+	 */
177
+	public static function course_archive_wc_filter_free( $query ){
123 178
 
124
-        } // end for each order
179
+		if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
125 181
 
126
-        // if we reach this place we found no order
127
-        return false;
182
+			// setup the course meta query
183
+			$meta_query = self::get_free_courses_meta_query_args();
128 184
 
129
-    } // end get_learner_course_active_order_ids
185
+			// manipulate the query to return free courses
186
+			$query->set('meta_query', $meta_query );
130 187
 
131
-    /**
132
-     * Output WooCommerce specific course filters
133
-     * Removing the paged argument
134
-     *
135
-     * @since 1.9.0
136
-     * @param $filter_links
137
-     * @return mixed
138
-     */
139
-    public static function add_course_archive_wc_filter_links( $filter_links ){
188
+			// don't show any paid courses
189
+			$courses = self::get_paid_courses();
190
+			$ids = array();
191
+			foreach( $courses as $course ){
192
+				$ids[] = $course->ID;
193
+			}
194
+			$query->set( 'post__not_in', $ids );
140 195
 
141
-        $free_courses = self::get_free_courses();
142
-        $paid_courses = self::get_paid_courses();
196
+		}// end if course_filter
143 197
 
144
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
-            // do not show any WooCommerce filters if all courses are
146
-            // free or if all courses are paid
147
-            return $filter_links;
198
+		return $query;
148 199
 
149
-        }
200
+	}// course_archive_wc_filter_free
150 201
 
151
-        $filter_links[] = array(
152
-            'id'=>'paid' ,
153
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
-            'title'=>__( 'Paid', 'woothemes-sensei' )
155
-        );
202
+	/**
203
+	 * Apply the paid filter to the course query on the courses page
204
+	 * will include all course with a product attached with a price
205
+	 * more than 0
206
+	 *
207
+	 * hooked into pre_get_posts
208
+	 *
209
+	 * @since 1.9.0
210
+	 * @param WP_Query $query
211
+	 * @return WP_Query $query
212
+	 */
213
+	public static function course_archive_wc_filter_paid( $query ){
156 214
 
157
-        $filter_links[] = array(
158
-            'id'=>'free',
159
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
-            'title'=>__( 'Free', 'woothemes-sensei' )
161
-        );
215
+		if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query() ){
162 217
 
163
-        return $filter_links;
218
+			// setup the course meta query
219
+			$meta_query = self::get_paid_courses_meta_query_args();
164 220
 
165
-    }// end add_course_archive_wc_filter_links
221
+			// manipulate the query to return free courses
222
+			$query->set('meta_query', $meta_query );
166 223
 
167
-    /**
168
-     * Apply the free filter the the course query
169
-     * getting all course with no products or products with zero price
170
-     *
171
-     * hooked into pre_get_posts
172
-     *
173
-     * @since 1.9.0
174
-     * @param WP_Query $query
175
-     * @return WP_Query $query
176
-     */
177
-    public static function course_archive_wc_filter_free( $query ){
224
+		}
178 225
 
179
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
226
+		return $query;
181 227
 
182
-            // setup the course meta query
183
-            $meta_query = self::get_free_courses_meta_query_args();
228
+	}
184 229
 
185
-            // manipulate the query to return free courses
186
-            $query->set('meta_query', $meta_query );
230
+	/**
231
+	 * Load the WooCommerce single product actions above
232
+	 * single courses if woocommerce is active allowing purchase
233
+	 * information and actions to be hooked from WooCommerce.
234
+	 */
235
+	public static function do_single_course_wc_single_product_action(){
187 236
 
188
-            // don't show any paid courses
189
-            $courses = self::get_paid_courses();
190
-            $ids = array();
191
-            foreach( $courses as $course ){
192
-                $ids[] = $course->ID;
193
-            }
194
-            $query->set( 'post__not_in', $ids );
237
+		/**
238
+		 * this hooks is documented within the WooCommerce plugin.
239
+		 */
240
+		if ( Sensei_WC::is_woocommerce_active() ) {
195 241
 
196
-        }// end if course_filter
242
+			do_action( 'woocommerce_before_single_product' );
197 243
 
198
-        return $query;
244
+		} // End If Statement
199 245
 
200
-    }// course_archive_wc_filter_free
246
+	}// end do_single_course_wc_single_product_action
201 247
 
202
-    /**
203
-     * Apply the paid filter to the course query on the courses page
204
-     * will include all course with a product attached with a price
205
-     * more than 0
206
-     *
207
-     * hooked into pre_get_posts
208
-     *
209
-     * @since 1.9.0
210
-     * @param WP_Query $query
211
-     * @return WP_Query $query
212
-     */
213
-    public static function course_archive_wc_filter_paid( $query ){
248
+	/**
249
+	 * Hooking into the single lesson page to alter the
250
+	 * user access permissions based on if they have purchased the
251
+	 * course the lesson belongs to.
252
+	 *
253
+	 * This function will only return false or the passed in user_access value.
254
+	 * It doesn't return true in order to avoid altering other options.
255
+	 *
256
+	 * @since 1.9.0
257
+	 *
258
+	 * @param $can_user_view_lesson
259
+	 * @param $lesson_id
260
+	 * @param $user_id
261
+	 * @return bool
262
+	 */
263
+	public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
214 264
 
215
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
217
-
218
-            // setup the course meta query
219
-            $meta_query = self::get_paid_courses_meta_query_args();
220
-
221
-            // manipulate the query to return free courses
222
-            $query->set('meta_query', $meta_query );
223
-
224
-        }
225
-
226
-        return $query;
227
-
228
-    }
229
-
230
-    /**
231
-     * Load the WooCommerce single product actions above
232
-     * single courses if woocommerce is active allowing purchase
233
-     * information and actions to be hooked from WooCommerce.
234
-     */
235
-    public static function do_single_course_wc_single_product_action(){
236
-
237
-        /**
238
-         * this hooks is documented within the WooCommerce plugin.
239
-         */
240
-        if ( Sensei_WC::is_woocommerce_active() ) {
241
-
242
-            do_action( 'woocommerce_before_single_product' );
243
-
244
-        } // End If Statement
245
-
246
-    }// end do_single_course_wc_single_product_action
247
-
248
-    /**
249
-     * Hooking into the single lesson page to alter the
250
-     * user access permissions based on if they have purchased the
251
-     * course the lesson belongs to.
252
-     *
253
-     * This function will only return false or the passed in user_access value.
254
-     * It doesn't return true in order to avoid altering other options.
255
-     *
256
-     * @since 1.9.0
257
-     *
258
-     * @param $can_user_view_lesson
259
-     * @param $lesson_id
260
-     * @param $user_id
261
-     * @return bool
262
-     */
263
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
264
-
265
-	    // do not override access to admins
266
-	    $course_id = Sensei()->lesson->get_course_id( $lesson_id );
267
-	    if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id )
268
-	         || Sensei_Utils::user_started_course( $course_id, $user_id )  ){
265
+		// do not override access to admins
266
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
267
+		if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id )
268
+			 || Sensei_Utils::user_started_course( $course_id, $user_id )  ){
269 269
 
270 270
 			return true;
271 271
 
272
-	    }
272
+		}
273 273
 
274
-        // check if the course has a valid product attached to it
275
-        // which the user should have purchased if they want to access
276
-        // the current lesson
277
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
278
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
279
-        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
280
-        if( isset ($product) && is_object($product) ){
274
+		// check if the course has a valid product attached to it
275
+		// which the user should have purchased if they want to access
276
+		// the current lesson
277
+		$course_id = get_post_meta( $lesson_id , '_lesson_course', true);
278
+		$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
279
+		$product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
280
+		if( isset ($product) && is_object($product) ){
281 281
 
282
-            // valid product found
283
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
282
+			// valid product found
283
+			$order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
284 284
 
285
-            // product has a successful order so this user may access the content
286
-            // this function may only return false or the default
287
-            // returning true may override other negatives which we don't want
288
-            if( ! $order_id ){
285
+			// product has a successful order so this user may access the content
286
+			// this function may only return false or the default
287
+			// returning true may override other negatives which we don't want
288
+			if( ! $order_id ){
289 289
 
290
-                return false;
290
+				return false;
291 291
 
292
-            }
292
+			}
293 293
 
294
-        }
294
+		}
295 295
 
296
-        // return the passed in value
297
-        return $can_user_view_lesson;
296
+		// return the passed in value
297
+		return $can_user_view_lesson;
298 298
 
299
-    }
299
+	}
300 300
 
301
-    /**
302
-     * Add course link to order thank you and details pages.
303
-     *
304
-     * @since  1.4.5
305
-     * @access public
306
-     *
307
-     * @return void
308
-     */
309
-    public static function course_link_from_order( ) {
301
+	/**
302
+	 * Add course link to order thank you and details pages.
303
+	 *
304
+	 * @since  1.4.5
305
+	 * @access public
306
+	 *
307
+	 * @return void
308
+	 */
309
+	public static function course_link_from_order( ) {
310 310
 
311
-        if( ! is_order_received_page() ){
312
-            return;
313
-        }
311
+		if( ! is_order_received_page() ){
312
+			return;
313
+		}
314 314
 
315
-        $order_id = get_query_var( 'order-received' );
315
+		$order_id = get_query_var( 'order-received' );
316 316
 		$order = new WC_Order( $order_id );
317 317
 
318 318
 		// exit early if not wc-completed or wc-processing
319 319
 		if( 'wc-completed' != $order->post_status
320
-            && 'wc-processing' != $order->post_status  ) {
321
-            return;
322
-        }
320
+			&& 'wc-processing' != $order->post_status  ) {
321
+			return;
322
+		}
323 323
 
324
-        $course_links = array(); // store the for links for courses purchased
324
+		$course_links = array(); // store the for links for courses purchased
325 325
 		foreach ( $order->get_items() as $item ) {
326 326
 
327
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
327
+			if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
328 328
 
329
-                // If item has variation_id then its a variation of the product
330
-                $item_id = $item['variation_id'];
329
+				// If item has variation_id then its a variation of the product
330
+				$item_id = $item['variation_id'];
331 331
 
332
-            } else {
332
+			} else {
333 333
 
334
-                //If not its real product set its id to item_id
335
-                $item_id = $item['product_id'];
334
+				//If not its real product set its id to item_id
335
+				$item_id = $item['product_id'];
336 336
 
337
-            } // End If Statement
337
+			} // End If Statement
338 338
 
339
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
339
+			$user_id = get_post_meta( $order->id, '_customer_user', true );
340 340
 
341
-            if( $user_id ) {
341
+			if( $user_id ) {
342 342
 
343
-                // Get all courses for product
344
-                $args = Sensei_Course::get_default_query_args();
345
-                $args['meta_query'] = array( array(
346
-                            'key' => '_course_woocommerce_product',
347
-                            'value' => $item_id
348
-                        ) );
349
-                $args['orderby'] = 'menu_order date';
350
-                $args['order'] = 'ASC';
343
+				// Get all courses for product
344
+				$args = Sensei_Course::get_default_query_args();
345
+				$args['meta_query'] = array( array(
346
+							'key' => '_course_woocommerce_product',
347
+							'value' => $item_id
348
+						) );
349
+				$args['orderby'] = 'menu_order date';
350
+				$args['order'] = 'ASC';
351 351
 
352
-                // loop through courses
353
-                $courses = get_posts( $args );
354
-                if( $courses && count( $courses ) > 0 ) {
352
+				// loop through courses
353
+				$courses = get_posts( $args );
354
+				if( $courses && count( $courses ) > 0 ) {
355 355
 
356
-                    foreach( $courses as $course ) {
356
+					foreach( $courses as $course ) {
357 357
 
358
-                        $title = $course->post_title;
359
-                        $permalink = get_permalink( $course->ID );
360
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
358
+						$title = $course->post_title;
359
+						$permalink = get_permalink( $course->ID );
360
+						$course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
361 361
 
362
-                    } // end for each
362
+					} // end for each
363 363
 
364
-                    // close the message div
364
+					// close the message div
365 365
 
366
-                }// end if $courses check
367
-            }
368
-        }// end loop through orders
366
+				}// end if $courses check
367
+			}
368
+		}// end loop through orders
369 369
 
370
-        // add the courses to the WooCommerce notice
371
-        if( ! empty( $course_links) ){
370
+		// add the courses to the WooCommerce notice
371
+		if( ! empty( $course_links) ){
372 372
 
373
-            $courses_html = _nx(
374
-                'You have purchased the following course:',
375
-                'You have purchased the following courses:',
376
-                count( $course_links ),
377
-                'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
378
-            );
373
+			$courses_html = _nx(
374
+				'You have purchased the following course:',
375
+				'You have purchased the following courses:',
376
+				count( $course_links ),
377
+				'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
378
+			);
379 379
 
380
-            foreach( $course_links as $link ){
380
+			foreach( $course_links as $link ){
381 381
 
382
-                $courses_html .= '<li>' . $link . '</li>';
382
+				$courses_html .= '<li>' . $link . '</li>';
383 383
 
384
-            }
384
+			}
385 385
 
386
-            $courses_html .= ' </ul>';
386
+			$courses_html .= ' </ul>';
387 387
 
388
-            wc_add_notice( $courses_html, 'success' );
389
-        }
388
+			wc_add_notice( $courses_html, 'success' );
389
+		}
390 390
 
391 391
 	} // end course_link_order_form
392 392
 
393
-    /**
394
-     * Show the message that a user should complete
395
-     * their purchase if the course is in the cart
396
-     *
397
-     * This should be used within the course loop or single course page
398
-     *
399
-     * @since 1.9.0
400
-     */
401
-    public static function course_in_cart_message(){
393
+	/**
394
+	 * Show the message that a user should complete
395
+	 * their purchase if the course is in the cart
396
+	 *
397
+	 * This should be used within the course loop or single course page
398
+	 *
399
+	 * @since 1.9.0
400
+	 */
401
+	public static function course_in_cart_message(){
402 402
 
403
-        global $post;
403
+		global $post;
404 404
 
405
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
405
+		if( self::is_course_in_cart( $post->ID ) ){ ?>
406 406
 
407 407
             <div class="sensei-message info">
408 408
                 <?php
409 409
 
410
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
411
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
412
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
410
+				$cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
411
+							  . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
412
+							  . __('complete the purchase', 'woothemes-sensei') . '</a>';
413 413
 
414
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
414
+				echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
415 415
 
416
-                ?>
416
+				?>
417 417
             </div>
418 418
         <?php }
419 419
 
420
-    } // End sensei_woocommerce_in_cart_message()
420
+	} // End sensei_woocommerce_in_cart_message()
421
+
422
+	/**
423
+	 * Checks the cart to see if a course is in the cart.
424
+	 *
425
+	 * @param $course_id
426
+	 * @return bool
427
+	 */
428
+	public static function is_course_in_cart( $course_id ){
429
+
430
+		$wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
431
+		$user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
432
+
433
+		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
434
+
435
+			if ( self::is_product_in_cart( $wc_post_id ) ) {
436
+
437
+				return true;
438
+
439
+			}
440
+
441
+		}
442
+
443
+		return false;
444
+
445
+	}// is_course_in_cart
446
+
447
+	/**
448
+	 * Check the cart to see if the product is in the cart
449
+	 *
450
+	 * @param $product_id
451
+	 * @return bool
452
+	 */
453
+	public static function is_product_in_cart( $product_id ){
454
+
455
+		if ( 0 < $product_id ) {
456
+
457
+			$product = wc_get_product( $product_id );
458
+
459
+			$parent_id = '';
460
+			if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
461
+				$wc_product_id = $product->parent->id;
462
+			}
463
+			foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
464
+
465
+				$cart_product = $values['data'];
466
+				if( $product_id == $cart_product->id ) {
467
+
468
+					return true;
469
+
470
+				}
471
+
472
+			}
473
+		} // End If Statement
474
+
475
+		return false;
476
+
477
+	} // end is_product_in_car
478
+
479
+	/**
480
+	 * Get all free WooCommerce products
481
+	 *
482
+	 * @since 1.9.0
483
+	 *
484
+	 * @return array $free_products{
485
+	 *  @type int $wp_post_id
486
+	 * }
487
+	 */
488
+	public static function get_free_product_ids(){
489
+
490
+		return  get_posts( array(
491
+			'post_type' => 'product',
492
+			'posts_per_page' => '1000',
493
+			'fields' => 'ids',
494
+			'meta_query'=> array(
495
+				'relation' => 'OR',
496
+				array(
497
+					'key'=> '_regular_price',
498
+					'value' => 0,
499
+				),
500
+				array(
501
+					'key'=> '_sale_price',
502
+					'value' => 0,
503
+				),
504
+			),
505
+		));
506
+
507
+	}// end get free product query
508
+
509
+	/**
510
+	 * The metat query for courses that are free
511
+	 *
512
+	 * @since 1.9.0
513
+	 * @return array $wp_meta_query_param
514
+	 */
515
+	public static function get_free_courses_meta_query_args(){
516
+
517
+		return array(
518
+			'relation' => 'OR',
519
+			array(
520
+				'key'     => '_course_woocommerce_product',
521
+				'value' => '-',
522
+				'compare' => '=',
523
+			),
524
+			array(
525
+				'key'     => '_course_woocommerce_product',
526
+				'value' => self::get_free_product_ids(),
527
+				'compare' => 'IN',
528
+			),
529
+		);
530
+
531
+	}// get_free_courses_meta_query
532
+
533
+	/**
534
+	 * The metat query for courses that are free
535
+	 *
536
+	 * @since 1.9.0
537
+	 * @return array $wp_query_meta_query_args_param
538
+	 */
539
+	public static function get_paid_courses_meta_query_args(){
540
+
541
+		$paid_product_ids = self::get_paid_product_ids();
542
+
543
+		return array(
544
+			array(
545
+				'key'     => '_course_woocommerce_product',
546
+				// when empty we give a false post_id to ensure the caller doesn't get any courses for their
547
+				// query
548
+				'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
549
+				'compare' => 'IN',
550
+			),
551
+		);
552
+
553
+	}// get_free_courses_meta_query
554
+
555
+	/**
556
+	 * The WordPress Query args
557
+	 * for paid products on sale
558
+	 *
559
+	 * @since 1.9.0
560
+	 * @return array $product_query_args
561
+	 */
562
+	public static function get_paid_products_on_sale_query_args(){
563
+
564
+		$args = array(
565
+				   'post_type' 		=> 'product',
566
+				   'posts_per_page' 		=> 1000,
567
+				   'orderby'         	=> 'date',
568
+				   'order'           	=> 'DESC',
569
+				   'suppress_filters' 	=> 0
570
+		);
571
+
572
+		$args[ 'fields' ]     = 'ids';
573
+
574
+		$args[ 'meta_query' ] = array(
575
+			'relation' => 'AND',
576
+			array(
577
+				'key'=> '_regular_price',
578
+				'compare' => '>',
579
+				'value' => 0,
580
+			),
581
+			array(
582
+				'key'=> '_sale_price',
583
+				'compare' => '>',
584
+				'value' => 0,
585
+			),
586
+		);
587
+
588
+		return $args;
589
+
590
+	} // get_paid_products_on_sale_query_args
591
+
592
+
593
+	/**
594
+	 * Return the WordPress query args for
595
+	 * products not on sale but that is not a free
596
+	 *
597
+	 * @since 1.9.0
598
+	 *
599
+	 * @return array
600
+	 */
601
+	public static function get_paid_products_not_on_sale_query_args(){
602
+
603
+		$args = array(
604
+			'post_type' 		=> 'product',
605
+			'posts_per_page' 		=> 1000,
606
+			'orderby'         	=> 'date',
607
+			'order'           	=> 'DESC',
608
+			'suppress_filters' 	=> 0
609
+		);
610
+
611
+		$args[ 'fields' ]     = 'ids';
612
+		$args[ 'meta_query' ] = array(
613
+			'relation' => 'AND',
614
+			array(
615
+				'key'=> '_regular_price',
616
+				'compare' => '>',
617
+				'value' => 0,
618
+			),
619
+			array(
620
+				'key'=> '_sale_price',
621
+				'compare' => '=',
622
+				'value' => '',
623
+			),
624
+		);
625
+
626
+		return $args;
627
+
628
+
629
+	} // get_paid_courses_meta_query
630
+
631
+	/**
632
+	 * Get all WooCommerce non-free product id's
633
+	 *
634
+	 * @since 1.9.0
635
+	 *
636
+	 * @return array $woocommerce_paid_product_ids
637
+	 */
638
+	public static function get_paid_product_ids(){
639
+
640
+		// get all the paid WooCommerce products that has regular
641
+		// and sale price greater than 0
642
+		// will be used later to check for course with the id as meta
643
+		$paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
644
+
645
+		// get all the paid WooCommerce products that has regular price
646
+		// greater than 0 without a sale price
647
+		// will be used later to check for course with the id as meta
648
+		$paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
649
+
650
+		// combine products ID's with regular and sale price grater than zero and those without
651
+		// sale but regular price greater than zero
652
+		$woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
653
+
654
+		// if
655
+		if( empty($woocommerce_paid_product_ids) ){
656
+			return array( );
657
+		}
658
+		return $woocommerce_paid_product_ids;
659
+
660
+	}
661
+
662
+	/**
663
+	 * Get all free courses.
664
+	 *
665
+	 * This course that have a WC product attached
666
+	 * that has a price or sale price of zero and
667
+	 * other courses with no WooCommerce products
668
+	 * attached.
669
+	 *
670
+	 * @since 1.9.0
671
+	 *
672
+	 * @return array
673
+	 */
674
+	public static function get_free_courses(){
675
+
676
+		$free_course_query_args = Sensei_Course::get_default_query_args();
677
+		$free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
678
+
679
+		// don't show any paid courses
680
+		$courses = self::get_paid_courses();
681
+		$ids = array();
682
+		foreach( $courses as $course ){
683
+			$ids[] = $course->ID;
684
+		}
685
+		$free_course_query_args[ 'post__not_in' ] =  $ids;
686
+
687
+		return get_posts( $free_course_query_args );
688
+
689
+	}
690
+
691
+	/**
692
+	 * Return all products that are not free
693
+	 *
694
+	 * @since 1.9.0
695
+	 * @return array
696
+	 */
697
+	public static function get_paid_courses(){
698
+
699
+		$paid_course_query_args = Sensei_Course::get_default_query_args();
700
+
701
+		$paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
702
+
703
+		return get_posts(  $paid_course_query_args );
704
+	}
705
+
706
+	/**
707
+	 * Show the WooCommerce add to cart button for the  current course
708
+	 *
709
+	 * The function will only show the button if
710
+	 * 1- the user can buy the course
711
+	 * 2- if they have completed their pre-requisite
712
+	 * 3- if the course has a valid product attached
713
+	 *
714
+	 * @since 1.9.0
715
+	 * @param int $course_id
716
+	 * @return string $html markup for the button or nothing if user not allowed to buy
717
+	 */
718
+	public static function the_add_to_cart_button_html( $course_id ){
719
+
720
+		if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
721
+			return '';
722
+		}
723
+
724
+		$wc_post_id = self::get_course_product_id( $course_id );
725
+
726
+		// Check if customer purchased the product
727
+		if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
728
+			|| empty( $wc_post_id ) ) {
729
+
730
+			return '';
731
+
732
+		}
733
+
734
+		// based on simple.php in WC templates/single-product/add-to-cart/
735
+		// Get the product
736
+		$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
737
+
738
+		// do not show the button for invalid products, non purchasable products, out
739
+		// of stock product or if course is already in cart
740
+		if ( ! isset ( $product )
741
+			|| ! is_object( $product )
742
+			|| ! $product->is_purchasable()
743
+			|| ! $product->is_in_stock()
744
+			|| self::is_course_in_cart( $wc_post_id ) ) {
745
+
746
+			return '';
747
+
748
+		}
421 749
 
422
-    /**
423
-     * Checks the cart to see if a course is in the cart.
424
-     *
425
-     * @param $course_id
426
-     * @return bool
427
-     */
428
-    public static function is_course_in_cart( $course_id ){
429
-
430
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
431
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
432
-
433
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
434
-
435
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
436
-
437
-                return true;
438
-
439
-            }
440
-
441
-        }
442
-
443
-        return false;
444
-
445
-    }// is_course_in_cart
446
-
447
-    /**
448
-     * Check the cart to see if the product is in the cart
449
-     *
450
-     * @param $product_id
451
-     * @return bool
452
-     */
453
-    public static function is_product_in_cart( $product_id ){
454
-
455
-        if ( 0 < $product_id ) {
456
-
457
-            $product = wc_get_product( $product_id );
458
-
459
-            $parent_id = '';
460
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
461
-                $wc_product_id = $product->parent->id;
462
-            }
463
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
464
-
465
-                $cart_product = $values['data'];
466
-                if( $product_id == $cart_product->id ) {
467
-
468
-                    return true;
469
-
470
-                }
471
-
472
-            }
473
-        } // End If Statement
474
-
475
-        return false;
476
-
477
-    } // end is_product_in_car
478
-
479
-    /**
480
-     * Get all free WooCommerce products
481
-     *
482
-     * @since 1.9.0
483
-     *
484
-     * @return array $free_products{
485
-     *  @type int $wp_post_id
486
-     * }
487
-     */
488
-    public static function get_free_product_ids(){
489
-
490
-        return  get_posts( array(
491
-            'post_type' => 'product',
492
-            'posts_per_page' => '1000',
493
-            'fields' => 'ids',
494
-            'meta_query'=> array(
495
-                'relation' => 'OR',
496
-                array(
497
-                    'key'=> '_regular_price',
498
-                    'value' => 0,
499
-                ),
500
-                array(
501
-                    'key'=> '_sale_price',
502
-                    'value' => 0,
503
-                ),
504
-            ),
505
-        ));
506
-
507
-    }// end get free product query
508
-
509
-    /**
510
-     * The metat query for courses that are free
511
-     *
512
-     * @since 1.9.0
513
-     * @return array $wp_meta_query_param
514
-     */
515
-    public static function get_free_courses_meta_query_args(){
516
-
517
-        return array(
518
-            'relation' => 'OR',
519
-            array(
520
-                'key'     => '_course_woocommerce_product',
521
-                'value' => '-',
522
-                'compare' => '=',
523
-            ),
524
-            array(
525
-                'key'     => '_course_woocommerce_product',
526
-                'value' => self::get_free_product_ids(),
527
-                'compare' => 'IN',
528
-            ),
529
-        );
530
-
531
-    }// get_free_courses_meta_query
532
-
533
-    /**
534
-     * The metat query for courses that are free
535
-     *
536
-     * @since 1.9.0
537
-     * @return array $wp_query_meta_query_args_param
538
-     */
539
-    public static function get_paid_courses_meta_query_args(){
540
-
541
-        $paid_product_ids = self::get_paid_product_ids();
542
-
543
-        return array(
544
-            array(
545
-                'key'     => '_course_woocommerce_product',
546
-                // when empty we give a false post_id to ensure the caller doesn't get any courses for their
547
-                // query
548
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
549
-                'compare' => 'IN',
550
-            ),
551
-        );
552
-
553
-    }// get_free_courses_meta_query
554
-
555
-    /**
556
-     * The WordPress Query args
557
-     * for paid products on sale
558
-     *
559
-     * @since 1.9.0
560
-     * @return array $product_query_args
561
-     */
562
-    public static function get_paid_products_on_sale_query_args(){
563
-
564
-        $args = array(
565
-                   'post_type' 		=> 'product',
566
-                   'posts_per_page' 		=> 1000,
567
-                   'orderby'         	=> 'date',
568
-                   'order'           	=> 'DESC',
569
-                   'suppress_filters' 	=> 0
570
-        );
571
-
572
-        $args[ 'fields' ]     = 'ids';
573
-
574
-        $args[ 'meta_query' ] = array(
575
-            'relation' => 'AND',
576
-            array(
577
-                'key'=> '_regular_price',
578
-                'compare' => '>',
579
-                'value' => 0,
580
-            ),
581
-            array(
582
-                'key'=> '_sale_price',
583
-                'compare' => '>',
584
-                'value' => 0,
585
-            ),
586
-        );
587
-
588
-        return $args;
589
-
590
-    } // get_paid_products_on_sale_query_args
591
-
592
-
593
-    /**
594
-     * Return the WordPress query args for
595
-     * products not on sale but that is not a free
596
-     *
597
-     * @since 1.9.0
598
-     *
599
-     * @return array
600
-     */
601
-    public static function get_paid_products_not_on_sale_query_args(){
602
-
603
-        $args = array(
604
-            'post_type' 		=> 'product',
605
-            'posts_per_page' 		=> 1000,
606
-            'orderby'         	=> 'date',
607
-            'order'           	=> 'DESC',
608
-            'suppress_filters' 	=> 0
609
-        );
610
-
611
-        $args[ 'fields' ]     = 'ids';
612
-        $args[ 'meta_query' ] = array(
613
-            'relation' => 'AND',
614
-            array(
615
-                'key'=> '_regular_price',
616
-                'compare' => '>',
617
-                'value' => 0,
618
-            ),
619
-            array(
620
-                'key'=> '_sale_price',
621
-                'compare' => '=',
622
-                'value' => '',
623
-            ),
624
-        );
625
-
626
-        return $args;
627
-
628
-
629
-    } // get_paid_courses_meta_query
630
-
631
-    /**
632
-     * Get all WooCommerce non-free product id's
633
-     *
634
-     * @since 1.9.0
635
-     *
636
-     * @return array $woocommerce_paid_product_ids
637
-     */
638
-    public static function get_paid_product_ids(){
639
-
640
-        // get all the paid WooCommerce products that has regular
641
-        // and sale price greater than 0
642
-        // will be used later to check for course with the id as meta
643
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
644
-
645
-        // get all the paid WooCommerce products that has regular price
646
-        // greater than 0 without a sale price
647
-        // will be used later to check for course with the id as meta
648
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
649
-
650
-        // combine products ID's with regular and sale price grater than zero and those without
651
-        // sale but regular price greater than zero
652
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
653
-
654
-        // if
655
-        if( empty($woocommerce_paid_product_ids) ){
656
-            return array( );
657
-        }
658
-        return $woocommerce_paid_product_ids;
659
-
660
-    }
661
-
662
-    /**
663
-     * Get all free courses.
664
-     *
665
-     * This course that have a WC product attached
666
-     * that has a price or sale price of zero and
667
-     * other courses with no WooCommerce products
668
-     * attached.
669
-     *
670
-     * @since 1.9.0
671
-     *
672
-     * @return array
673
-     */
674
-    public static function get_free_courses(){
675
-
676
-        $free_course_query_args = Sensei_Course::get_default_query_args();
677
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
678
-
679
-        // don't show any paid courses
680
-        $courses = self::get_paid_courses();
681
-        $ids = array();
682
-        foreach( $courses as $course ){
683
-            $ids[] = $course->ID;
684
-        }
685
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
686
-
687
-        return get_posts( $free_course_query_args );
688
-
689
-    }
690
-
691
-    /**
692
-     * Return all products that are not free
693
-     *
694
-     * @since 1.9.0
695
-     * @return array
696
-     */
697
-    public static function get_paid_courses(){
698
-
699
-        $paid_course_query_args = Sensei_Course::get_default_query_args();
700
-
701
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
702
-
703
-        return get_posts(  $paid_course_query_args );
704
-    }
705
-
706
-    /**
707
-     * Show the WooCommerce add to cart button for the  current course
708
-     *
709
-     * The function will only show the button if
710
-     * 1- the user can buy the course
711
-     * 2- if they have completed their pre-requisite
712
-     * 3- if the course has a valid product attached
713
-     *
714
-     * @since 1.9.0
715
-     * @param int $course_id
716
-     * @return string $html markup for the button or nothing if user not allowed to buy
717
-     */
718
-    public static function the_add_to_cart_button_html( $course_id ){
719
-
720
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
721
-            return '';
722
-        }
723
-
724
-        $wc_post_id = self::get_course_product_id( $course_id );
725
-
726
-        // Check if customer purchased the product
727
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
728
-            || empty( $wc_post_id ) ) {
729
-
730
-            return '';
731
-
732
-        }
733
-
734
-        // based on simple.php in WC templates/single-product/add-to-cart/
735
-        // Get the product
736
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
737
-
738
-        // do not show the button for invalid products, non purchasable products, out
739
-        // of stock product or if course is already in cart
740
-        if ( ! isset ( $product )
741
-            || ! is_object( $product )
742
-            || ! $product->is_purchasable()
743
-            || ! $product->is_in_stock()
744
-            || self::is_course_in_cart( $wc_post_id ) ) {
745
-
746
-            return '';
747
-
748
-        }
749
-
750
-        //
751
-        // button  output:
752
-        //
753
-        ?>
750
+		//
751
+		// button  output:
752
+		//
753
+		?>
754 754
 
755 755
         <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
756 756
               class="cart"
@@ -783,69 +783,69 @@  discard block
 block discarded – undo
783 783
         </form>
784 784
 
785 785
         <?php
786
-    } // end the_add_to_cart_button_html
786
+	} // end the_add_to_cart_button_html
787 787
 
788
-    /**
789
-     * Alter the no permissions message on the single course page
790
-     * Changes the message to a WooCommerce specific message.
791
-     *
792
-     * @since 1.9.0
793
-     *
794
-     * @param $message
795
-     * @param $post_id
796
-     *
797
-     * @return string $message
798
-     */
799
-    public static function alter_no_permissions_message( $message, $post_id ){
788
+	/**
789
+	 * Alter the no permissions message on the single course page
790
+	 * Changes the message to a WooCommerce specific message.
791
+	 *
792
+	 * @since 1.9.0
793
+	 *
794
+	 * @param $message
795
+	 * @param $post_id
796
+	 *
797
+	 * @return string $message
798
+	 */
799
+	public static function alter_no_permissions_message( $message, $post_id ){
800 800
 
801
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
802
-            return  $message;
803
-        }
801
+		if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
802
+			return  $message;
803
+		}
804 804
 
805
-        $product_id = self::get_course_product_id( $post_id );
805
+		$product_id = self::get_course_product_id( $post_id );
806 806
 
807
-        if( ! $product_id
808
-            || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
807
+		if( ! $product_id
808
+			|| ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
809 809
 
810
-            return $message;
810
+			return $message;
811 811
 
812
-        }
812
+		}
813 813
 
814
-        ob_start();
815
-        self::the_course_no_permissions_message( $post_id );
816
-        $woocommerce_course_no_permissions_message = ob_get_clean();
814
+		ob_start();
815
+		self::the_course_no_permissions_message( $post_id );
816
+		$woocommerce_course_no_permissions_message = ob_get_clean();
817 817
 
818
-        return $woocommerce_course_no_permissions_message ;
818
+		return $woocommerce_course_no_permissions_message ;
819 819
 
820
-    }
821
-    /**
822
-     * Show the no permissions message when a user is logged in
823
-     * and have not yet purchased the current course
824
-     *
825
-     * @since 1.9.0
826
-     */
827
-    public static function the_course_no_permissions_message( $course_id ){
820
+	}
821
+	/**
822
+	 * Show the no permissions message when a user is logged in
823
+	 * and have not yet purchased the current course
824
+	 *
825
+	 * @since 1.9.0
826
+	 */
827
+	public static function the_course_no_permissions_message( $course_id ){
828 828
 
829
-        // login link
830
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
831
-	    $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
832
-	    $wc_product_id =  self::get_course_product_id( $course_id );
829
+		// login link
830
+		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
831
+		$login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
832
+		$wc_product_id =  self::get_course_product_id( $course_id );
833 833
 
834
-	    if ( self::is_product_in_cart( $wc_product_id ) ) {
834
+		if ( self::is_product_in_cart( $wc_product_id ) ) {
835 835
 
836
-		    $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>';
836
+			$cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>';
837 837
 
838
-		    $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link );
839
-		    ?>
838
+			$message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link );
839
+			?>
840 840
 		    <span class="add-to-cart-login">
841 841
 		            <?php echo $message; ?>
842 842
 		        </span>
843 843
 
844 844
 		    <?php
845 845
 
846
-	    } elseif ( is_user_logged_in() ) {
846
+		} elseif ( is_user_logged_in() ) {
847 847
 
848
-		    ?>
848
+			?>
849 849
 		    <style>
850 850
 			    .sensei-message.alert {
851 851
 				    display: none;
@@ -854,346 +854,346 @@  discard block
 block discarded – undo
854 854
 
855 855
 		    <?php
856 856
 
857
-	    } else {
857
+		} else {
858 858
 
859
-		    $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
860
-	        ?>
859
+			$message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
860
+			?>
861 861
 		        <span class="add-to-cart-login">
862 862
 		            <?php echo $message; ?>
863 863
 		        </span>
864 864
 
865 865
 	        <?php
866
-	    }
867
-    }
866
+		}
867
+	}
868 868
 
869
-    /**
870
-     * Checks if a user has bought a product item.
871
-     *
872
-     * @since  1.9.0
873
-     *
874
-     * @param  int $user_id
875
-     * @param  int $product_id
876
-     *
877
-     * @return bool
878
-     */
879
-    public static function has_customer_bought_product ( $user_id, $product_id ){
880
-
881
-        $orders = self::get_user_product_orders( $user_id, $product_id );
882
-
883
-        foreach ( $orders as $order_id ) {
884
-
885
-            $order = new WC_Order( $order_id->ID );
886
-
887
-            // wc-active is the subscriptions complete status
888
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) )
889
-                || ! ( 0 < sizeof( $order->get_items() ) )  ){
890
-
891
-                continue;
869
+	/**
870
+	 * Checks if a user has bought a product item.
871
+	 *
872
+	 * @since  1.9.0
873
+	 *
874
+	 * @param  int $user_id
875
+	 * @param  int $product_id
876
+	 *
877
+	 * @return bool
878
+	 */
879
+	public static function has_customer_bought_product ( $user_id, $product_id ){
892 880
 
893
-            }
881
+		$orders = self::get_user_product_orders( $user_id, $product_id );
894 882
 
895
-            foreach( $order->get_items() as $item ) {
883
+		foreach ( $orders as $order_id ) {
896 884
 
897
-                // Check if user has bought product
898
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
885
+			$order = new WC_Order( $order_id->ID );
899 886
 
900
-                    // Check if user has an active subscription for product
901
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
902
-                        $sub_key = wcs_get_subscription( $order );
903
-                        if( $sub_key ) {
904
-                            $sub = wcs_get_subscription( $sub_key );
905
-                            if( $sub && isset( $sub['status'] ) ) {
906
-                                if( 'active' == $sub['status'] ) {
907
-                                    return true;
908
-                                } else {
909
-                                    return false;
910
-                                }
911
-                            }
912
-                        }
913
-                    }
887
+			// wc-active is the subscriptions complete status
888
+			if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) )
889
+				|| ! ( 0 < sizeof( $order->get_items() ) )  ){
914 890
 
915
-                    // Customer has bought product
916
-                    return true;
917
-                } // End If Statement
891
+				continue;
918 892
 
919
-            } // End For each item
893
+			}
920 894
 
921
-        } // End For each order
895
+			foreach( $order->get_items() as $item ) {
922 896
 
923
-	    // default is no order
924
-	    return false;
897
+				// Check if user has bought product
898
+				if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
925 899
 
926
-    } // end has customer bought product
900
+					// Check if user has an active subscription for product
901
+					if( class_exists( 'WC_Subscriptions_Manager' ) ) {
902
+						$sub_key = wcs_get_subscription( $order );
903
+						if( $sub_key ) {
904
+							$sub = wcs_get_subscription( $sub_key );
905
+							if( $sub && isset( $sub['status'] ) ) {
906
+								if( 'active' == $sub['status'] ) {
907
+									return true;
908
+								} else {
909
+									return false;
910
+								}
911
+							}
912
+						}
913
+					}
927 914
 
928
-    /**
929
-     * Return the product id for the given course
930
-     *
931
-     * @since 1.9.0
932
-     *
933
-     * @param int $course_id
934
-     *
935
-     * @return string $woocommerce_product_id or false if none exist
936
-     *
937
-     */
938
-    public static function get_course_product_id( $course_id ){
915
+					// Customer has bought product
916
+					return true;
917
+				} // End If Statement
939 918
 
940
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
919
+			} // End For each item
941 920
 
942
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
943
-            return false;
944
-        }
921
+		} // End For each order
945 922
 
946
-        return $product_id;
923
+		// default is no order
924
+		return false;
947 925
 
948
-    }
926
+	} // end has customer bought product
949 927
 
950
-    /**
951
-     * Alter the body classes adding WooCommerce to the body
952
-     *
953
-     * Speciall cases where this is needed is template no-permissions.php
954
-     *
955
-     * @param array $classes
956
-     * @return array
957
-     */
958
-    public static function add_woocommerce_body_class( $classes ){
928
+	/**
929
+	 * Return the product id for the given course
930
+	 *
931
+	 * @since 1.9.0
932
+	 *
933
+	 * @param int $course_id
934
+	 *
935
+	 * @return string $woocommerce_product_id or false if none exist
936
+	 *
937
+	 */
938
+	public static function get_course_product_id( $course_id ){
939
+
940
+		$product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
941
+
942
+		if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
943
+			return false;
944
+		}
945
+
946
+		return $product_id;
947
+
948
+	}
949
+
950
+	/**
951
+	 * Alter the body classes adding WooCommerce to the body
952
+	 *
953
+	 * Speciall cases where this is needed is template no-permissions.php
954
+	 *
955
+	 * @param array $classes
956
+	 * @return array
957
+	 */
958
+	public static function add_woocommerce_body_class( $classes ){
959 959
 
960
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
960
+		if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
961 961
 
962
-            $classes[] ='woocommerce';
962
+			$classes[] ='woocommerce';
963 963
 
964
-        }
964
+		}
965 965
 
966
-        return $classes;
966
+		return $classes;
967 967
 
968
-    }
968
+	}
969 969
 
970
-    /**
971
-     * Responds to when a subscription product is purchased
972
-     *
973
-     * @since   1.2.0
974
-     * @since  1.9.0 move to class Sensei_WC
975
-     *
976
-     * @param   WC_Order $order
977
-     *
978
-     * @return  void
979
-     */
980
-    public static function activate_subscription(  $order ) {
970
+	/**
971
+	 * Responds to when a subscription product is purchased
972
+	 *
973
+	 * @since   1.2.0
974
+	 * @since  1.9.0 move to class Sensei_WC
975
+	 *
976
+	 * @param   WC_Order $order
977
+	 *
978
+	 * @return  void
979
+	 */
980
+	public static function activate_subscription(  $order ) {
981 981
 
982
-        $order_user = get_user_by('id', $order->user_id);
983
-        $user['ID'] = $order_user->ID;
984
-        $user['user_login'] = $order_user->user_login;
985
-        $user['user_email'] = $order_user->user_email;
986
-        $user['user_url'] = $order_user->user_url;
982
+		$order_user = get_user_by('id', $order->user_id);
983
+		$user['ID'] = $order_user->ID;
984
+		$user['user_login'] = $order_user->user_login;
985
+		$user['user_email'] = $order_user->user_email;
986
+		$user['user_url'] = $order_user->user_url;
987 987
 
988
-        // Run through each product ordered
989
-        if ( ! sizeof($order->get_items() )>0 ) {
988
+		// Run through each product ordered
989
+		if ( ! sizeof($order->get_items() )>0 ) {
990 990
 
991
-            return;
991
+			return;
992 992
 
993
-        }
993
+		}
994 994
 
995
-        foreach($order->get_items() as $item) {
995
+		foreach($order->get_items() as $item) {
996 996
 
997
-            $product_type = '';
997
+			$product_type = '';
998 998
 
999
-            if (isset($item['variation_id']) && $item['variation_id'] > 0) {
999
+			if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1000 1000
 
1001
-                $item_id = $item['variation_id'];
1002
-                $product_type = 'subscription_variation';
1001
+				$item_id = $item['variation_id'];
1002
+				$product_type = 'subscription_variation';
1003 1003
 
1004
-            } else {
1004
+			} else {
1005 1005
 
1006
-                $item_id = $item['product_id'];
1006
+				$item_id = $item['product_id'];
1007 1007
 
1008
-            } // End If Statement
1008
+			} // End If Statement
1009 1009
 
1010
-            $_product = self::get_product_object( $item_id, $product_type );
1010
+			$_product = self::get_product_object( $item_id, $product_type );
1011 1011
 
1012
-            // Get courses that use the WC product
1013
-            $courses = array();
1012
+			// Get courses that use the WC product
1013
+			$courses = array();
1014 1014
 
1015
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1015
+			if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1016 1016
 
1017
-                $courses = Sensei()->course->get_product_courses( $item_id );
1017
+				$courses = Sensei()->course->get_product_courses( $item_id );
1018 1018
 
1019
-            } // End If Statement
1019
+			} // End If Statement
1020 1020
 
1021
-            // Loop and add the user to the course.
1022
-            foreach ( $courses as $course_item ){
1021
+			// Loop and add the user to the course.
1022
+			foreach ( $courses as $course_item ){
1023 1023
 
1024
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1024
+				Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1025 1025
 
1026
-            } // End For Loop
1026
+			} // End For Loop
1027 1027
 
1028
-        } // End For Loop
1028
+		} // End For Loop
1029 1029
 
1030
-    } // End activate_subscription()
1030
+	} // End activate_subscription()
1031 1031
 
1032
-    /**
1033
-     * Adds detail to to the WooCommerce order
1034
-     *
1035
-     * @since   1.4.5
1036
-     * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details
1037
-     *
1038
-     * @param   WC_Order $order
1039
-     *
1040
-     * @return  void
1041
-     */
1042
-    public static function email_course_details(  $order ){
1032
+	/**
1033
+	 * Adds detail to to the WooCommerce order
1034
+	 *
1035
+	 * @since   1.4.5
1036
+	 * @since 1.9.0 function moved to class Sensei_WC and renamed from sensei_woocommerce_email_course_details to email_course_details
1037
+	 *
1038
+	 * @param   WC_Order $order
1039
+	 *
1040
+	 * @return  void
1041
+	 */
1042
+	public static function email_course_details(  $order ){
1043 1043
 
1044
-        global $woocommerce;
1044
+		global $woocommerce;
1045 1045
 
1046
-        // exit early if not wc-completed or wc-processing
1047
-        if( 'wc-completed' != $order->post_status
1048
-            && 'wc-processing' != $order->post_status  ) {
1049
-            return;
1050
-        }
1046
+		// exit early if not wc-completed or wc-processing
1047
+		if( 'wc-completed' != $order->post_status
1048
+			&& 'wc-processing' != $order->post_status  ) {
1049
+			return;
1050
+		}
1051 1051
 
1052
-        $order_items = $order->get_items();
1053
-        $order_id = $order->id;
1052
+		$order_items = $order->get_items();
1053
+		$order_id = $order->id;
1054 1054
 
1055
-        //If object have items go through them all to find course
1056
-        if ( 0 < sizeof( $order_items ) ) {
1055
+		//If object have items go through them all to find course
1056
+		if ( 0 < sizeof( $order_items ) ) {
1057 1057
 
1058
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1059
-            $order_contains_courses = false;
1058
+			$course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1059
+			$order_contains_courses = false;
1060 1060
 
1061 1061
 
1062
-            foreach ( $order_items as $item ) {
1062
+			foreach ( $order_items as $item ) {
1063 1063
 
1064
-                $product_type = '';
1065
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1066
-                    // If item has variation_id then its from variation
1067
-                    $item_id = $item['variation_id'];
1068
-                    $product_type = 'variation';
1069
-                } else {
1070
-                    // If not its real product set its id to item_id
1071
-                    $item_id = $item['product_id'];
1072
-                } // End If Statement
1064
+				$product_type = '';
1065
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1066
+					// If item has variation_id then its from variation
1067
+					$item_id = $item['variation_id'];
1068
+					$product_type = 'variation';
1069
+				} else {
1070
+					// If not its real product set its id to item_id
1071
+					$item_id = $item['product_id'];
1072
+				} // End If Statement
1073 1073
 
1074
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1074
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1075 1075
 
1076
-                if( $user_id ) {
1076
+				if( $user_id ) {
1077 1077
 
1078
-                    // Get all courses for product
1079
-                    $args = array(
1080
-                        'posts_per_page' => -1,
1081
-                        'post_type' => 'course',
1082
-                        'meta_query' => array(
1083
-                            array(
1084
-                                'key' => '_course_woocommerce_product',
1085
-                                'value' => $item_id
1086
-                            )
1087
-                        ),
1088
-                        'orderby' => 'menu_order date',
1089
-                        'order' => 'ASC',
1090
-                    );
1091
-                    $courses = get_posts( $args );
1078
+					// Get all courses for product
1079
+					$args = array(
1080
+						'posts_per_page' => -1,
1081
+						'post_type' => 'course',
1082
+						'meta_query' => array(
1083
+							array(
1084
+								'key' => '_course_woocommerce_product',
1085
+								'value' => $item_id
1086
+							)
1087
+						),
1088
+						'orderby' => 'menu_order date',
1089
+						'order' => 'ASC',
1090
+					);
1091
+					$courses = get_posts( $args );
1092 1092
 
1093
-                    if( $courses && count( $courses ) > 0 ) {
1093
+					if( $courses && count( $courses ) > 0 ) {
1094 1094
 
1095
-                        foreach( $courses as $course ) {
1095
+						foreach( $courses as $course ) {
1096 1096
 
1097
-                            $title = $course->post_title;
1098
-                            $permalink = get_permalink( $course->ID );
1099
-                            $order_contains_courses = true;
1100
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1101
-                        }
1097
+							$title = $course->post_title;
1098
+							$permalink = get_permalink( $course->ID );
1099
+							$order_contains_courses = true;
1100
+							$course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1101
+						}
1102 1102
 
1103 1103
 
1104
-                    } // end if has courses
1104
+					} // end if has courses
1105 1105
 
1106
-                } // end if $userPid
1106
+				} // end if $userPid
1107 1107
 
1108
-            } // end for each order item
1108
+			} // end for each order item
1109 1109
 
1110
-            // Output Course details
1111
-            if( $order_contains_courses ){
1110
+			// Output Course details
1111
+			if( $order_contains_courses ){
1112 1112
 
1113
-                echo $course_details_html;
1113
+				echo $course_details_html;
1114 1114
 
1115
-            }
1115
+			}
1116 1116
 
1117 1117
 
1118
-        } // end if  order items not empty
1118
+		} // end if  order items not empty
1119 1119
 
1120
-    }// end email_course_details
1120
+	}// end email_course_details
1121 1121
 
1122
-    /**
1123
-     * sensei_woocommerce_complete_order description
1124
-     * @since   1.0.3
1125
-     * @access  public
1126
-     * @param   int $order_id WC order ID
1127
-     * @return  void
1128
-     */
1129
-    public static function complete_order ( $order_id = 0 ) {
1122
+	/**
1123
+	 * sensei_woocommerce_complete_order description
1124
+	 * @since   1.0.3
1125
+	 * @access  public
1126
+	 * @param   int $order_id WC order ID
1127
+	 * @return  void
1128
+	 */
1129
+	public static function complete_order ( $order_id = 0 ) {
1130 1130
 
1131
-        $order_user = array();
1131
+		$order_user = array();
1132 1132
 
1133
-        // Check for WooCommerce
1134
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1135
-            // Get order object
1136
-            $order = new WC_Order( $order_id );
1133
+		// Check for WooCommerce
1134
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1135
+			// Get order object
1136
+			$order = new WC_Order( $order_id );
1137 1137
 
1138
-	        if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) {
1138
+			if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) {
1139 1139
 
1140
-		        return;
1140
+				return;
1141 1141
 
1142
-	        }
1142
+			}
1143 1143
 
1144
-            $user = get_user_by( 'id', $order->get_user_id() );
1145
-            $order_user['ID'] = $user->ID;
1146
-            $order_user['user_login'] = $user->user_login;
1147
-            $order_user['user_email'] = $user->user_email;
1148
-            $order_user['user_url'] = $user->user_url;
1149
-            // Run through each product ordered
1150
-            if ( 0 < sizeof( $order->get_items() ) ) {
1144
+			$user = get_user_by( 'id', $order->get_user_id() );
1145
+			$order_user['ID'] = $user->ID;
1146
+			$order_user['user_login'] = $user->user_login;
1147
+			$order_user['user_email'] = $user->user_email;
1148
+			$order_user['user_url'] = $user->user_url;
1149
+			// Run through each product ordered
1150
+			if ( 0 < sizeof( $order->get_items() ) ) {
1151 1151
 
1152
-                foreach( $order->get_items() as $item ) {
1152
+				foreach( $order->get_items() as $item ) {
1153 1153
 
1154
-                    $product_type = '';
1155
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1154
+					$product_type = '';
1155
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1156 1156
 
1157
-                        $item_id = $item['variation_id'];
1158
-                        $product_type = 'variation';
1157
+						$item_id = $item['variation_id'];
1158
+						$product_type = 'variation';
1159 1159
 
1160
-                    } else {
1160
+					} else {
1161 1161
 
1162
-                        $item_id = $item['product_id'];
1162
+						$item_id = $item['product_id'];
1163 1163
 
1164
-                    } // End If Statement
1164
+					} // End If Statement
1165 1165
 
1166
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1166
+					$_product = Sensei_WC::get_product_object( $item_id, $product_type );
1167 1167
 
1168
-                    // Get courses that use the WC product
1169
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1168
+					// Get courses that use the WC product
1169
+					$courses = Sensei()->course->get_product_courses( $_product->id );
1170 1170
 
1171
-                    // Loop and update those courses
1172
-                    foreach ( $courses as $course_item ) {
1171
+					// Loop and update those courses
1172
+					foreach ( $courses as $course_item ) {
1173 1173
 
1174
-                        $update_course = self::course_update( $course_item->ID, $order_user );
1174
+						$update_course = self::course_update( $course_item->ID, $order_user );
1175 1175
 
1176
-                    } // End For Loop
1176
+					} // End For Loop
1177 1177
 
1178
-                } // End For Loop
1178
+				} // End For Loop
1179 1179
 
1180
-            } // End If Statement
1181
-            // Add meta to indicate that payment has been completed successfully
1182
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1180
+			} // End If Statement
1181
+			// Add meta to indicate that payment has been completed successfully
1182
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1183 1183
 
1184
-        } // End If Statement
1184
+		} // End If Statement
1185 1185
 
1186
-    } // End sensei_woocommerce_complete_order()
1186
+	} // End sensei_woocommerce_complete_order()
1187 1187
 
1188
-    /**
1189
-     * Responds to when an order is cancelled.
1190
-     *
1191
-     * @since   1.2.0
1192
-     * @since   1.9.0 Move function to the Sensei_WC class
1193
-     * @param   integer| WC_Order $order_id order ID
1194
-     * @return  void
1195
-     */
1196
-    public static function cancel_order ( $order_id ) {
1188
+	/**
1189
+	 * Responds to when an order is cancelled.
1190
+	 *
1191
+	 * @since   1.2.0
1192
+	 * @since   1.9.0 Move function to the Sensei_WC class
1193
+	 * @param   integer| WC_Order $order_id order ID
1194
+	 * @return  void
1195
+	 */
1196
+	public static function cancel_order ( $order_id ) {
1197 1197
 
1198 1198
 		// Get order object
1199 1199
 		if( is_object( $order_id ) ){
@@ -1211,428 +1211,428 @@  discard block
 block discarded – undo
1211 1211
 
1212 1212
 		}
1213 1213
 
1214
-        // Run through each product ordered
1215
-        if ( 0 < sizeof( $order->get_items() ) ) {
1214
+		// Run through each product ordered
1215
+		if ( 0 < sizeof( $order->get_items() ) ) {
1216 1216
 
1217
-            // Get order user
1218
-            $user_id = $order->__get( 'user_id' );
1217
+			// Get order user
1218
+			$user_id = $order->__get( 'user_id' );
1219 1219
 
1220
-            foreach( $order->get_items() as $item ) {
1220
+			foreach( $order->get_items() as $item ) {
1221 1221
 
1222
-                $product_type = '';
1223
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1222
+				$product_type = '';
1223
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1224 1224
 
1225
-                    $item_id = $item['variation_id'];
1226
-                    $product_type = 'variation';
1225
+					$item_id = $item['variation_id'];
1226
+					$product_type = 'variation';
1227 1227
 
1228
-                } else {
1228
+				} else {
1229 1229
 
1230
-                    $item_id = $item['product_id'];
1230
+					$item_id = $item['product_id'];
1231 1231
 
1232
-                } // End If Statement
1232
+				} // End If Statement
1233 1233
 
1234
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1234
+				$_product = Sensei_WC::get_product_object( $item_id, $product_type );
1235 1235
 
1236
-                // Get courses that use the WC product
1237
-                $courses = array();
1238
-                $courses = Sensei()->course->get_product_courses( $item_id );
1236
+				// Get courses that use the WC product
1237
+				$courses = array();
1238
+				$courses = Sensei()->course->get_product_courses( $item_id );
1239 1239
 
1240
-                // Loop and update those courses
1241
-                foreach ($courses as $course_item){
1240
+				// Loop and update those courses
1241
+				foreach ($courses as $course_item){
1242 1242
 
1243
-	                if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){
1244
-		                continue;
1245
-	                }
1246
-                    // Check and Remove course from courses user meta
1247
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1243
+					if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){
1244
+						continue;
1245
+					}
1246
+					// Check and Remove course from courses user meta
1247
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1248 1248
 
1249
-                } // End For Loop
1249
+				} // End For Loop
1250 1250
 
1251
-            } // End For Loop
1251
+			} // End For Loop
1252 1252
 
1253
-        } // End If Statement
1253
+		} // End If Statement
1254 1254
 
1255
-    } // End sensei_woocommerce_cancel_order()
1255
+	} // End sensei_woocommerce_cancel_order()
1256 1256
 
1257
-    /**
1258
-     * Returns the WooCommerce Product Object
1259
-     *
1260
-     * The code caters for pre and post WooCommerce 2.2 installations.
1261
-     *
1262
-     * @since   1.1.1
1263
-     * @access  public
1264
-     * @param   integer $wc_product_id Product ID or Variation ID
1265
-     * @param   string  $product_type  '' or 'variation'
1266
-     * @return   WC_Product $wc_product_object
1267
-     */
1268
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1257
+	/**
1258
+	 * Returns the WooCommerce Product Object
1259
+	 *
1260
+	 * The code caters for pre and post WooCommerce 2.2 installations.
1261
+	 *
1262
+	 * @since   1.1.1
1263
+	 * @access  public
1264
+	 * @param   integer $wc_product_id Product ID or Variation ID
1265
+	 * @param   string  $product_type  '' or 'variation'
1266
+	 * @return   WC_Product $wc_product_object
1267
+	 */
1268
+	public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1269 1269
 
1270
-        $wc_product_object = false;
1271
-        if ( 0 < intval( $wc_product_id ) ) {
1270
+		$wc_product_object = false;
1271
+		if ( 0 < intval( $wc_product_id ) ) {
1272 1272
 
1273
-            // Get the product
1274
-            if ( function_exists( 'wc_get_product' ) ) {
1273
+			// Get the product
1274
+			if ( function_exists( 'wc_get_product' ) ) {
1275 1275
 
1276
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1276
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1277 1277
 
1278
-            } elseif ( function_exists( 'get_product' ) ) {
1278
+			} elseif ( function_exists( 'get_product' ) ) {
1279 1279
 
1280
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1280
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1281 1281
 
1282
-            } else {
1282
+			} else {
1283 1283
 
1284
-                // Pre WC 2.0
1285
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1284
+				// Pre WC 2.0
1285
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1286 1286
 
1287
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1287
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1288 1288
 
1289
-                } else {
1289
+				} else {
1290 1290
 
1291
-                    $wc_product_object = new WC_Product( $wc_product_id );
1291
+					$wc_product_object = new WC_Product( $wc_product_id );
1292 1292
 
1293
-                } // End If Statement
1293
+				} // End If Statement
1294 1294
 
1295
-            } // End If Statement
1295
+			} // End If Statement
1296 1296
 
1297
-        } // End If Statement
1297
+		} // End If Statement
1298 1298
 
1299
-        return $wc_product_object;
1299
+		return $wc_product_object;
1300 1300
 
1301
-    } // End sensei_get_woocommerce_product_object()
1301
+	} // End sensei_get_woocommerce_product_object()
1302 1302
 
1303
-    /**
1304
-     * If customer has purchased the course, update Sensei to indicate that they are taking the course.
1305
-     *
1306
-     * @since  1.0.0
1307
-     * @since 1.9.0 move to class Sensei_WC
1308
-     *
1309
-     * @param  int 			$course_id  (default: 0)
1310
-     * @param  array/Object $order_user (default: array()) Specific user's data.
1311
-     *
1312
-     * @return bool|int
1313
-     */
1314
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1303
+	/**
1304
+	 * If customer has purchased the course, update Sensei to indicate that they are taking the course.
1305
+	 *
1306
+	 * @since  1.0.0
1307
+	 * @since 1.9.0 move to class Sensei_WC
1308
+	 *
1309
+	 * @param  int 			$course_id  (default: 0)
1310
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
1311
+	 *
1312
+	 * @return bool|int
1313
+	 */
1314
+	public static function course_update ( $course_id = 0, $order_user = array()  ) {
1315 1315
 
1316
-        global $current_user;
1316
+		global $current_user;
1317 1317
 
1318
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1318
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1319 1319
 
1320
-        $data_update = false;
1320
+		$data_update = false;
1321 1321
 
1322
-        // Get the product ID
1323
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1322
+		// Get the product ID
1323
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1324 1324
 
1325
-        // Check if in the admin
1326
-        if ( is_admin() ) {
1325
+		// Check if in the admin
1326
+		if ( is_admin() ) {
1327 1327
 
1328
-            $user_login = $order_user['user_login'];
1329
-            $user_email = $order_user['user_email'];
1330
-            $user_url = $order_user['user_url'];
1331
-            $user_id = $order_user['ID'];
1328
+			$user_login = $order_user['user_login'];
1329
+			$user_email = $order_user['user_email'];
1330
+			$user_url = $order_user['user_url'];
1331
+			$user_id = $order_user['ID'];
1332 1332
 
1333
-        } else {
1333
+		} else {
1334 1334
 
1335
-            $user_login = $current_user->user_login;
1336
-            $user_email = $current_user->user_email;
1337
-            $user_url = $current_user->user_url;
1338
-            $user_id = $current_user->ID;
1335
+			$user_login = $current_user->user_login;
1336
+			$user_email = $current_user->user_email;
1337
+			$user_url = $current_user->user_url;
1338
+			$user_id = $current_user->ID;
1339 1339
 
1340
-        } // End If Statement
1340
+		} // End If Statement
1341 1341
 
1342
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1343
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1344
-        if( 0 < absint( $course_prerequisite_id ) ) {
1342
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1343
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1344
+		if( 0 < absint( $course_prerequisite_id ) ) {
1345 1345
 
1346
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1347
-            if ( ! $prereq_course_complete ) {
1346
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1347
+			if ( ! $prereq_course_complete ) {
1348 1348
 
1349
-                // Remove all course user meta
1350
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1349
+				// Remove all course user meta
1350
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1351 1351
 
1352
-            }
1353
-        }
1352
+			}
1353
+		}
1354 1354
 
1355
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1355
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1356 1356
 
1357
-        if ( ! $is_user_taking_course
1358
-            && Sensei_WC::is_woocommerce_active()
1359
-            && 0 < $wc_post_id
1360
-            && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) {
1357
+		if ( ! $is_user_taking_course
1358
+			&& Sensei_WC::is_woocommerce_active()
1359
+			&& 0 < $wc_post_id
1360
+			&& Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) {
1361 1361
 
1362
-	            $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) );
1362
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) );
1363 1363
 
1364
-	            if ( true == $activity_logged ) {
1364
+				if ( true == $activity_logged ) {
1365 1365
 
1366
-		            $is_user_taking_course = true;
1366
+					$is_user_taking_course = true;
1367 1367
 
1368
-	            } // End If Statement
1368
+				} // End If Statement
1369 1369
 
1370
-        }// end if is user taking course
1370
+		}// end if is user taking course
1371 1371
 
1372
-        return $is_user_taking_course;
1372
+		return $is_user_taking_course;
1373 1373
 
1374
-    } // End course_update()
1374
+	} // End course_update()
1375 1375
 
1376
-    /**
1377
-     * Disable guest checkout if a course product is in the cart
1378
-     *
1379
-     * @since 1.1.0
1380
-     * @since 1.9.0 move to class Sensei_WC
1381
-     *
1382
-     * @param  boolean $guest_checkout Current guest checkout setting
1383
-     *
1384
-     * @return boolean                 Modified guest checkout setting
1385
-     */
1386
-    public static function disable_guest_checkout( $guest_checkout ) {
1376
+	/**
1377
+	 * Disable guest checkout if a course product is in the cart
1378
+	 *
1379
+	 * @since 1.1.0
1380
+	 * @since 1.9.0 move to class Sensei_WC
1381
+	 *
1382
+	 * @param  boolean $guest_checkout Current guest checkout setting
1383
+	 *
1384
+	 * @return boolean                 Modified guest checkout setting
1385
+	 */
1386
+	public static function disable_guest_checkout( $guest_checkout ) {
1387 1387
 
1388
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1388
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1389 1389
 
1390
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1390
+			if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1391 1391
 
1392
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1393
-                    if( isset( $product['product_id'] ) ) {
1392
+				foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1393
+					if( isset( $product['product_id'] ) ) {
1394 1394
 
1395
-                        $args = array(
1396
-                            'posts_per_page' => -1,
1397
-                            'post_type' => 'course',
1398
-                            'meta_query' => array(
1399
-                                array(
1400
-                                    'key' => '_course_woocommerce_product',
1401
-                                    'value' => $product['product_id']
1402
-                                )
1403
-                            )
1404
-                        );
1395
+						$args = array(
1396
+							'posts_per_page' => -1,
1397
+							'post_type' => 'course',
1398
+							'meta_query' => array(
1399
+								array(
1400
+									'key' => '_course_woocommerce_product',
1401
+									'value' => $product['product_id']
1402
+								)
1403
+							)
1404
+						);
1405 1405
 
1406
-                        $posts = get_posts( $args );
1406
+						$posts = get_posts( $args );
1407 1407
 
1408
-                        if( $posts && count( $posts ) > 0 ) {
1408
+						if( $posts && count( $posts ) > 0 ) {
1409 1409
 
1410
-                            foreach( $posts as $course ) {
1411
-                                $guest_checkout = '';
1412
-                                break;
1410
+							foreach( $posts as $course ) {
1411
+								$guest_checkout = '';
1412
+								break;
1413 1413
 
1414
-                            }
1415
-                        }
1414
+							}
1415
+						}
1416 1416
 
1417
-                    }
1417
+					}
1418 1418
 
1419
-                }
1419
+				}
1420 1420
 
1421
-            }
1422
-        }
1421
+			}
1422
+		}
1423 1423
 
1424
-        return $guest_checkout;
1424
+		return $guest_checkout;
1425 1425
 
1426
-    }// end disable_guest_checkout
1426
+	}// end disable_guest_checkout
1427 1427
 
1428
-    /**
1429
-     * Change order status with virtual products to completed
1430
-     *
1431
-     * @since  1.1.0
1432
-     * @since 1.9.0 move to class Sensei_WC
1433
-     *
1434
-     * @param string $order_status
1435
-     * @param int $order_id
1436
-     *
1437
-     * @return string
1438
-     **/
1439
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1428
+	/**
1429
+	 * Change order status with virtual products to completed
1430
+	 *
1431
+	 * @since  1.1.0
1432
+	 * @since 1.9.0 move to class Sensei_WC
1433
+	 *
1434
+	 * @param string $order_status
1435
+	 * @param int $order_id
1436
+	 *
1437
+	 * @return string
1438
+	 **/
1439
+	public static function virtual_order_payment_complete( $order_status, $order_id ) {
1440 1440
 
1441
-        $order = new WC_Order( $order_id );
1441
+		$order = new WC_Order( $order_id );
1442 1442
 
1443
-        if ( ! isset ( $order ) ) return '';
1443
+		if ( ! isset ( $order ) ) return '';
1444 1444
 
1445
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1445
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1446 1446
 
1447
-            $virtual_order = true;
1447
+			$virtual_order = true;
1448 1448
 
1449
-            if ( count( $order->get_items() ) > 0 ) {
1449
+			if ( count( $order->get_items() ) > 0 ) {
1450 1450
 
1451
-                foreach( $order->get_items() as $item ) {
1451
+				foreach( $order->get_items() as $item ) {
1452 1452
 
1453
-                    if ( $item['product_id'] > 0 ) {
1454
-                        $_product = $order->get_product_from_item( $item );
1455
-                        if ( ! $_product->is_virtual() ) {
1453
+					if ( $item['product_id'] > 0 ) {
1454
+						$_product = $order->get_product_from_item( $item );
1455
+						if ( ! $_product->is_virtual() ) {
1456 1456
 
1457
-                            $virtual_order = false;
1458
-                            break;
1457
+							$virtual_order = false;
1458
+							break;
1459 1459
 
1460
-                        } // End If Statement
1460
+						} // End If Statement
1461 1461
 
1462
-                    } // End If Statement
1462
+					} // End If Statement
1463 1463
 
1464
-                } // End For Loop
1464
+				} // End For Loop
1465 1465
 
1466
-            } // End If Statement
1466
+			} // End If Statement
1467 1467
 
1468
-            // virtual order, mark as completed
1469
-            if ( $virtual_order ) {
1468
+			// virtual order, mark as completed
1469
+			if ( $virtual_order ) {
1470 1470
 
1471
-                return 'completed';
1471
+				return 'completed';
1472 1472
 
1473
-            } // End If Statement
1473
+			} // End If Statement
1474 1474
 
1475
-        } // End If Statement
1475
+		} // End If Statement
1476 1476
 
1477
-        return $order_status;
1477
+		return $order_status;
1478 1478
 
1479
-    }// end virtual_order_payment_complete
1479
+	}// end virtual_order_payment_complete
1480 1480
 
1481 1481
 
1482
-    /**
1483
-     * Determine if the user has and active subscription to give them access
1484
-     * to the requested resource.
1485
-     *
1486
-     * @since 1.9.0
1487
-     *
1488
-     * @param  boolean$user_access_permission
1489
-     * @param  integer $user_id
1490
-     * @return boolean $user_access_permission
1491
-     */
1492
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1482
+	/**
1483
+	 * Determine if the user has and active subscription to give them access
1484
+	 * to the requested resource.
1485
+	 *
1486
+	 * @since 1.9.0
1487
+	 *
1488
+	 * @param  boolean$user_access_permission
1489
+	 * @param  integer $user_id
1490
+	 * @return boolean $user_access_permission
1491
+	 */
1492
+	public static function get_subscription_permission( $user_access_permission, $user_id ){
1493 1493
 
1494
-        global $post;
1494
+		global $post;
1495 1495
 
1496
-        // ignore the current case if the following conditions are met
1497
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1498
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1499
-            || ! wcs_user_has_subscription( $user_id) ){
1496
+		// ignore the current case if the following conditions are met
1497
+		if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1498
+			|| ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1499
+			|| ! wcs_user_has_subscription( $user_id) ){
1500 1500
 
1501
-            return $user_access_permission;
1501
+			return $user_access_permission;
1502 1502
 
1503
-        }
1503
+		}
1504 1504
 
1505
-        // at this user has a subscription
1506
-        // is the subscription on the the current course?
1505
+		// at this user has a subscription
1506
+		// is the subscription on the the current course?
1507 1507
 
1508
-        $course_id = 0;
1509
-        if ( 'course' == $post->post_type ){
1508
+		$course_id = 0;
1509
+		if ( 'course' == $post->post_type ){
1510 1510
 
1511
-            $course_id = $post->ID;
1511
+			$course_id = $post->ID;
1512 1512
 
1513
-        } elseif ( 'lesson' == $post->post_type ) {
1513
+		} elseif ( 'lesson' == $post->post_type ) {
1514 1514
 
1515
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1515
+			$course_id = Sensei()->lesson->get_course_id( $post->ID );
1516 1516
 
1517
-        } else {
1517
+		} else {
1518 1518
 
1519
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1520
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1519
+			$lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1520
+			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1521 1521
 
1522
-        }
1522
+		}
1523 1523
 
1524
-        // if the course has no subscription WooCommerce product attached to return the permissions as is
1525
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1526
-        $product = wc_get_product( $product_id );
1527
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1524
+		// if the course has no subscription WooCommerce product attached to return the permissions as is
1525
+		$product_id = Sensei_WC::get_course_product_id( $course_id );
1526
+		$product = wc_get_product( $product_id );
1527
+		if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1528 1528
 
1529
-            return $user_access_permission;
1529
+			return $user_access_permission;
1530 1530
 
1531
-        }
1531
+		}
1532 1532
 
1533
-        // give access if user has active subscription on the product otherwise restrict it.
1534
-        // also check if the user was added to the course directly after the subscription started.
1535
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1536
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1537
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1533
+		// give access if user has active subscription on the product otherwise restrict it.
1534
+		// also check if the user was added to the course directly after the subscription started.
1535
+		if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1536
+			|| wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1537
+			|| self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1538 1538
 
1539
-            $user_access_permission = true;
1539
+			$user_access_permission = true;
1540 1540
 
1541
-        }else{
1541
+		}else{
1542 1542
 
1543
-            $user_access_permission = false;
1544
-            // do not show the WC permissions message
1545
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1546
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1547
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1548
-        }
1543
+			$user_access_permission = false;
1544
+			// do not show the WC permissions message
1545
+			remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1546
+			Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1547
+			Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1548
+		}
1549 1549
 
1550
-        return $user_access_permission;
1550
+		return $user_access_permission;
1551 1551
 
1552
-    } // end get_subscription_permission
1552
+	} // end get_subscription_permission
1553 1553
 
1554
-    /**
1555
-     * Get all the valid subscription types.
1556
-     *
1557
-     * @since 1.9.0
1558
-     * @return array
1559
-     */
1560
-    public static function get_subscription_types(){
1554
+	/**
1555
+	 * Get all the valid subscription types.
1556
+	 *
1557
+	 * @since 1.9.0
1558
+	 * @return array
1559
+	 */
1560
+	public static function get_subscription_types(){
1561 1561
 
1562
-        return array( 'subscription','subscription_variation','variable-subscription' );
1562
+		return array( 'subscription','subscription_variation','variable-subscription' );
1563 1563
 
1564
-    }
1564
+	}
1565 1565
 
1566
-    /**
1567
-     * Compare the user's subscriptions end date with the date
1568
-     * the user was added to the course. If the user was added after
1569
-     * the subscription ended they were manually added and this will return
1570
-     * true.
1571
-     *
1572
-     * Important to note that all subscriptions for the user is compared.
1573
-     *
1574
-     * @since 1.9.0
1575
-     *
1576
-     * @param $user_id
1577
-     * @param $product_id
1578
-     * @param $course_id
1579
-     *
1580
-     * @return bool
1581
-     */
1582
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1566
+	/**
1567
+	 * Compare the user's subscriptions end date with the date
1568
+	 * the user was added to the course. If the user was added after
1569
+	 * the subscription ended they were manually added and this will return
1570
+	 * true.
1571
+	 *
1572
+	 * Important to note that all subscriptions for the user is compared.
1573
+	 *
1574
+	 * @since 1.9.0
1575
+	 *
1576
+	 * @param $user_id
1577
+	 * @param $product_id
1578
+	 * @param $course_id
1579
+	 *
1580
+	 * @return bool
1581
+	 */
1582
+	public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1583 1583
 
1584
-        $course_start_date = '';
1585
-        $subscription_start_date = '';
1586
-        $is_a_subscription ='';
1587
-        $was_user_added_without_subscription = true;
1584
+		$course_start_date = '';
1585
+		$subscription_start_date = '';
1586
+		$is_a_subscription ='';
1587
+		$was_user_added_without_subscription = true;
1588 1588
 
1589
-        // if user is not on the course they were not added
1590
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1589
+		// if user is not on the course they were not added
1590
+		if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1591 1591
 
1592
-            return false;
1592
+			return false;
1593 1593
 
1594
-        }
1594
+		}
1595 1595
 
1596
-        // if user doesn't have a subscription and is taking the course
1597
-        // they were added manually
1598
-        if ( ! wcs_user_has_subscription($user_id, $product_id)
1599
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1596
+		// if user doesn't have a subscription and is taking the course
1597
+		// they were added manually
1598
+		if ( ! wcs_user_has_subscription($user_id, $product_id)
1599
+			&& Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1600 1600
 
1601
-            return true;
1601
+			return true;
1602 1602
 
1603
-        }
1603
+		}
1604 1604
 
1605
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1605
+		$course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1606 1606
 
1607
-        // comparing dates setup data
1608
-        $course_start_date = date_create( $course_status->comment_date );
1609
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1607
+		// comparing dates setup data
1608
+		$course_start_date = date_create( $course_status->comment_date );
1609
+		$subscriptions = wcs_get_users_subscriptions( $user_id );
1610 1610
 
1611
-        // comparing every subscription
1612
-        foreach( $subscriptions as $subscription ){
1611
+		// comparing every subscription
1612
+		foreach( $subscriptions as $subscription ){
1613 1613
 
1614
-            // for the following statuses we know the user was not added
1615
-            // manually
1616
-            $status = $subscription->get_status();
1617
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1614
+			// for the following statuses we know the user was not added
1615
+			// manually
1616
+			$status = $subscription->get_status();
1617
+			if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1618 1618
 
1619
-                continue;
1619
+				continue;
1620 1620
 
1621
-            }
1621
+			}
1622 1622
 
1623
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1623
+			$current_subscription_start_date = date_create( $subscription->modified_date );
1624 1624
 
1625
-            // is the last updated subscription date newer than course start date
1626
-            if (  $current_subscription_start_date > $course_start_date   ) {
1625
+			// is the last updated subscription date newer than course start date
1626
+			if (  $current_subscription_start_date > $course_start_date   ) {
1627 1627
 
1628
-                return false;
1628
+				return false;
1629 1629
 
1630
-            }
1630
+			}
1631 1631
 
1632
-        }
1632
+		}
1633 1633
 
1634
-        return $was_user_added_without_subscription;
1635
-    }
1634
+		return $was_user_added_without_subscription;
1635
+	}
1636 1636
 
1637 1637
 	/**
1638 1638
 	 * Get all the orders for a specific user and product combination
Please login to merge, or discard this patch.
Spacing   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,16 +11,16 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
     /**
16 16
      * Load the files needed for the woocommerce integration.
17 17
      *
18 18
      * @since 1.9.0
19 19
      */
20
-    public static function load_woocommerce_integration_hooks(){
20
+    public static function load_woocommerce_integration_hooks() {
21 21
 
22
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
23
-        require_once( $woocommerce_hooks_file_path );
22
+	    $woocommerce_hooks_file_path = Sensei()->plugin_path().'includes/hooks/woocommerce.php';
23
+        require_once($woocommerce_hooks_file_path);
24 24
 
25 25
     }
26 26
     /**
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
      * @since 1.9.0
30 30
      * @return bool
31 31
      */
32
-    public static function is_woocommerce_active(){
32
+    public static function is_woocommerce_active() {
33 33
 
34
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
35 35
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
36 36
 
37 37
     } // end is_woocommerce_active
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return bool
48 48
      */
49
-    public static function is_woocommerce_present(){
49
+    public static function is_woocommerce_present() {
50 50
 
51
-        $active_plugins = (array) get_option( 'active_plugins', array() );
51
+        $active_plugins = (array) get_option('active_plugins', array());
52 52
 
53
-        if ( is_multisite() ){
53
+        if (is_multisite()) {
54 54
 
55
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
56 56
 
57 57
         }
58 58
 
59
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
60 60
 
61
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
62 62
 
63 63
     }// end is_woocommerce_present
64 64
 
@@ -71,48 +71,48 @@  discard block
 block discarded – undo
71 71
      * @param $course_id
72 72
      * @return array $user_course_orders
73 73
      */
74
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
74
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
75 75
 
76
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
77 77
 
78
-        $orders_query = new WP_Query( array(
78
+        $orders_query = new WP_Query(array(
79 79
             'post_type'   => 'shop_order',
80 80
             'posts_per_page' => -1,
81
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
81
+            'post_status' => array('wc-processing', 'wc-completed'),
82 82
             'meta_key'=> '_customer_user',
83 83
             'meta_value'=> $user_id,
84
-        ) );
84
+        ));
85 85
 
86
-        if( $orders_query->post_count == 0 ){
86
+        if ($orders_query->post_count == 0) {
87 87
 
88 88
             return false;
89 89
 
90 90
         }
91 91
 
92
-        foreach( $orders_query->get_posts() as $order ){
92
+        foreach ($orders_query->get_posts() as $order) {
93 93
 
94
-            $order = new WC_Order( $order->ID );
94
+            $order = new WC_Order($order->ID);
95 95
             $items = $order->get_items();
96 96
 
97
-            $user_orders =  array();
97
+            $user_orders = array();
98 98
 
99
-            foreach( $items as $item ){
99
+            foreach ($items as $item) {
100 100
 
101 101
                 // if the product id on the order and the one given to this function
102 102
                 // this order has been placed by the given user on the given course.
103
-                $product = wc_get_product( $item['product_id'] );
103
+                $product = wc_get_product($item['product_id']);
104 104
 
105
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
105
+                if (is_object($product) && $product->is_type('variable')) {
106 106
 
107 107
                     $item_product_id = $item['variation_id'];
108 108
 
109 109
                 } else {
110 110
 
111
-                    $item_product_id =  $item['product_id'];
111
+                    $item_product_id = $item['product_id'];
112 112
 
113 113
                 }
114 114
 
115
-                if( $course_product_id == $item_product_id ){
115
+                if ($course_product_id == $item_product_id) {
116 116
 
117 117
                     return $order->id;
118 118
 
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
      * @param $filter_links
137 137
      * @return mixed
138 138
      */
139
-    public static function add_course_archive_wc_filter_links( $filter_links ){
139
+    public static function add_course_archive_wc_filter_links($filter_links) {
140 140
 
141 141
         $free_courses = self::get_free_courses();
142 142
         $paid_courses = self::get_paid_courses();
143 143
 
144
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
144
+        if (empty($free_courses) || empty($paid_courses)) {
145 145
             // do not show any WooCommerce filters if all courses are
146 146
             // free or if all courses are paid
147 147
             return $filter_links;
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
         }
150 150
 
151 151
         $filter_links[] = array(
152
-            'id'=>'paid' ,
153
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
154
-            'title'=>__( 'Paid', 'woothemes-sensei' )
152
+            'id'=>'paid',
153
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
154
+            'title'=>__('Paid', 'woothemes-sensei')
155 155
         );
156 156
 
157 157
         $filter_links[] = array(
158 158
             'id'=>'free',
159
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
160
-            'title'=>__( 'Free', 'woothemes-sensei' )
159
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
160
+            'title'=>__('Free', 'woothemes-sensei')
161 161
         );
162 162
 
163 163
         return $filter_links;
@@ -174,24 +174,24 @@  discard block
 block discarded – undo
174 174
      * @param WP_Query $query
175 175
      * @return WP_Query $query
176 176
      */
177
-    public static function course_archive_wc_filter_free( $query ){
177
+    public static function course_archive_wc_filter_free($query) {
178 178
 
179
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
180
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
179
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
180
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
181 181
 
182 182
             // setup the course meta query
183 183
             $meta_query = self::get_free_courses_meta_query_args();
184 184
 
185 185
             // manipulate the query to return free courses
186
-            $query->set('meta_query', $meta_query );
186
+            $query->set('meta_query', $meta_query);
187 187
 
188 188
             // don't show any paid courses
189 189
             $courses = self::get_paid_courses();
190 190
             $ids = array();
191
-            foreach( $courses as $course ){
191
+            foreach ($courses as $course) {
192 192
                 $ids[] = $course->ID;
193 193
             }
194
-            $query->set( 'post__not_in', $ids );
194
+            $query->set('post__not_in', $ids);
195 195
 
196 196
         }// end if course_filter
197 197
 
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
      * @param WP_Query $query
211 211
      * @return WP_Query $query
212 212
      */
213
-    public static function course_archive_wc_filter_paid( $query ){
213
+    public static function course_archive_wc_filter_paid($query) {
214 214
 
215
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
216
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
215
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
216
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
217 217
 
218 218
             // setup the course meta query
219 219
             $meta_query = self::get_paid_courses_meta_query_args();
220 220
 
221 221
             // manipulate the query to return free courses
222
-            $query->set('meta_query', $meta_query );
222
+            $query->set('meta_query', $meta_query);
223 223
 
224 224
         }
225 225
 
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
      * single courses if woocommerce is active allowing purchase
233 233
      * information and actions to be hooked from WooCommerce.
234 234
      */
235
-    public static function do_single_course_wc_single_product_action(){
235
+    public static function do_single_course_wc_single_product_action() {
236 236
 
237 237
         /**
238 238
          * this hooks is documented within the WooCommerce plugin.
239 239
          */
240
-        if ( Sensei_WC::is_woocommerce_active() ) {
240
+        if (Sensei_WC::is_woocommerce_active()) {
241 241
 
242
-            do_action( 'woocommerce_before_single_product' );
242
+            do_action('woocommerce_before_single_product');
243 243
 
244 244
         } // End If Statement
245 245
 
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
      * @param $user_id
261 261
      * @return bool
262 262
      */
263
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
264 264
 
265 265
 	    // do not override access to admins
266
-	    $course_id = Sensei()->lesson->get_course_id( $lesson_id );
267
-	    if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id )
268
-	         || Sensei_Utils::user_started_course( $course_id, $user_id )  ){
266
+	    $course_id = Sensei()->lesson->get_course_id($lesson_id);
267
+	    if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)
268
+	         || Sensei_Utils::user_started_course($course_id, $user_id)) {
269 269
 
270 270
 			return true;
271 271
 
@@ -274,18 +274,18 @@  discard block
 block discarded – undo
274 274
         // check if the course has a valid product attached to it
275 275
         // which the user should have purchased if they want to access
276 276
         // the current lesson
277
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
278
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
277
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
278
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
279 279
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
280
-        if( isset ($product) && is_object($product) ){
280
+        if (isset ($product) && is_object($product)) {
281 281
 
282 282
             // valid product found
283
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
283
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
284 284
 
285 285
             // product has a successful order so this user may access the content
286 286
             // this function may only return false or the default
287 287
             // returning true may override other negatives which we don't want
288
-            if( ! $order_id ){
288
+            if ( ! $order_id) {
289 289
 
290 290
                 return false;
291 291
 
@@ -308,23 +308,23 @@  discard block
 block discarded – undo
308 308
      */
309 309
     public static function course_link_from_order( ) {
310 310
 
311
-        if( ! is_order_received_page() ){
311
+        if ( ! is_order_received_page()) {
312 312
             return;
313 313
         }
314 314
 
315
-        $order_id = get_query_var( 'order-received' );
316
-		$order = new WC_Order( $order_id );
315
+        $order_id = get_query_var('order-received');
316
+		$order = new WC_Order($order_id);
317 317
 
318 318
 		// exit early if not wc-completed or wc-processing
319
-		if( 'wc-completed' != $order->post_status
320
-            && 'wc-processing' != $order->post_status  ) {
319
+		if ('wc-completed' != $order->post_status
320
+            && 'wc-processing' != $order->post_status) {
321 321
             return;
322 322
         }
323 323
 
324 324
         $course_links = array(); // store the for links for courses purchased
325
-		foreach ( $order->get_items() as $item ) {
325
+		foreach ($order->get_items() as $item) {
326 326
 
327
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
327
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
328 328
 
329 329
                 // If item has variation_id then its a variation of the product
330 330
                 $item_id = $item['variation_id'];
@@ -336,28 +336,28 @@  discard block
 block discarded – undo
336 336
 
337 337
             } // End If Statement
338 338
 
339
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
339
+            $user_id = get_post_meta($order->id, '_customer_user', true);
340 340
 
341
-            if( $user_id ) {
341
+            if ($user_id) {
342 342
 
343 343
                 // Get all courses for product
344 344
                 $args = Sensei_Course::get_default_query_args();
345
-                $args['meta_query'] = array( array(
345
+                $args['meta_query'] = array(array(
346 346
                             'key' => '_course_woocommerce_product',
347 347
                             'value' => $item_id
348
-                        ) );
348
+                        ));
349 349
                 $args['orderby'] = 'menu_order date';
350 350
                 $args['order'] = 'ASC';
351 351
 
352 352
                 // loop through courses
353
-                $courses = get_posts( $args );
354
-                if( $courses && count( $courses ) > 0 ) {
353
+                $courses = get_posts($args);
354
+                if ($courses && count($courses) > 0) {
355 355
 
356
-                    foreach( $courses as $course ) {
356
+                    foreach ($courses as $course) {
357 357
 
358 358
                         $title = $course->post_title;
359
-                        $permalink = get_permalink( $course->ID );
360
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
359
+                        $permalink = get_permalink($course->ID);
360
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
361 361
 
362 362
                     } // end for each
363 363
 
@@ -368,24 +368,24 @@  discard block
 block discarded – undo
368 368
         }// end loop through orders
369 369
 
370 370
         // add the courses to the WooCommerce notice
371
-        if( ! empty( $course_links) ){
371
+        if ( ! empty($course_links)) {
372 372
 
373 373
             $courses_html = _nx(
374 374
                 'You have purchased the following course:',
375 375
                 'You have purchased the following courses:',
376
-                count( $course_links ),
376
+                count($course_links),
377 377
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
378 378
             );
379 379
 
380
-            foreach( $course_links as $link ){
380
+            foreach ($course_links as $link) {
381 381
 
382
-                $courses_html .= '<li>' . $link . '</li>';
382
+                $courses_html .= '<li>'.$link.'</li>';
383 383
 
384 384
             }
385 385
 
386 386
             $courses_html .= ' </ul>';
387 387
 
388
-            wc_add_notice( $courses_html, 'success' );
388
+            wc_add_notice($courses_html, 'success');
389 389
         }
390 390
 
391 391
 	} // end course_link_order_form
@@ -398,20 +398,20 @@  discard block
 block discarded – undo
398 398
      *
399 399
      * @since 1.9.0
400 400
      */
401
-    public static function course_in_cart_message(){
401
+    public static function course_in_cart_message() {
402 402
 
403 403
         global $post;
404 404
 
405
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
405
+        if (self::is_course_in_cart($post->ID)) { ?>
406 406
 
407 407
             <div class="sensei-message info">
408 408
                 <?php
409 409
 
410
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
411
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
412
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
410
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
411
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
412
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
413 413
 
414
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
414
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
415 415
 
416 416
                 ?>
417 417
             </div>
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
      * @param $course_id
426 426
      * @return bool
427 427
      */
428
-    public static function is_course_in_cart( $course_id ){
428
+    public static function is_course_in_cart($course_id) {
429 429
 
430
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
431
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
430
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
431
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
432 432
 
433
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
433
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
434 434
 
435
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
435
+            if (self::is_product_in_cart($wc_post_id)) {
436 436
 
437 437
                 return true;
438 438
 
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
      * @param $product_id
451 451
      * @return bool
452 452
      */
453
-    public static function is_product_in_cart( $product_id ){
453
+    public static function is_product_in_cart($product_id) {
454 454
 
455
-        if ( 0 < $product_id ) {
455
+        if (0 < $product_id) {
456 456
 
457
-            $product = wc_get_product( $product_id );
457
+            $product = wc_get_product($product_id);
458 458
 
459 459
             $parent_id = '';
460
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
460
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
461 461
                 $wc_product_id = $product->parent->id;
462 462
             }
463
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
463
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
464 464
 
465 465
                 $cart_product = $values['data'];
466
-                if( $product_id == $cart_product->id ) {
466
+                if ($product_id == $cart_product->id) {
467 467
 
468 468
                     return true;
469 469
 
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
      *  @type int $wp_post_id
486 486
      * }
487 487
      */
488
-    public static function get_free_product_ids(){
488
+    public static function get_free_product_ids() {
489 489
 
490
-        return  get_posts( array(
490
+        return  get_posts(array(
491 491
             'post_type' => 'product',
492 492
             'posts_per_page' => '1000',
493 493
             'fields' => 'ids',
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
      * @since 1.9.0
513 513
      * @return array $wp_meta_query_param
514 514
      */
515
-    public static function get_free_courses_meta_query_args(){
515
+    public static function get_free_courses_meta_query_args() {
516 516
 
517 517
         return array(
518 518
             'relation' => 'OR',
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
      * @since 1.9.0
537 537
      * @return array $wp_query_meta_query_args_param
538 538
      */
539
-    public static function get_paid_courses_meta_query_args(){
539
+    public static function get_paid_courses_meta_query_args() {
540 540
 
541 541
         $paid_product_ids = self::get_paid_product_ids();
542 542
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
                 'key'     => '_course_woocommerce_product',
546 546
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
547 547
                 // query
548
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
548
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
549 549
                 'compare' => 'IN',
550 550
             ),
551 551
         );
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      * @since 1.9.0
560 560
      * @return array $product_query_args
561 561
      */
562
-    public static function get_paid_products_on_sale_query_args(){
562
+    public static function get_paid_products_on_sale_query_args() {
563 563
 
564 564
         $args = array(
565 565
                    'post_type' 		=> 'product',
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
                    'suppress_filters' 	=> 0
570 570
         );
571 571
 
572
-        $args[ 'fields' ]     = 'ids';
572
+        $args['fields']     = 'ids';
573 573
 
574
-        $args[ 'meta_query' ] = array(
574
+        $args['meta_query'] = array(
575 575
             'relation' => 'AND',
576 576
             array(
577 577
                 'key'=> '_regular_price',
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
      *
599 599
      * @return array
600 600
      */
601
-    public static function get_paid_products_not_on_sale_query_args(){
601
+    public static function get_paid_products_not_on_sale_query_args() {
602 602
 
603 603
         $args = array(
604 604
             'post_type' 		=> 'product',
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
             'suppress_filters' 	=> 0
609 609
         );
610 610
 
611
-        $args[ 'fields' ]     = 'ids';
612
-        $args[ 'meta_query' ] = array(
611
+        $args['fields']     = 'ids';
612
+        $args['meta_query'] = array(
613 613
             'relation' => 'AND',
614 614
             array(
615 615
                 'key'=> '_regular_price',
@@ -635,24 +635,24 @@  discard block
 block discarded – undo
635 635
      *
636 636
      * @return array $woocommerce_paid_product_ids
637 637
      */
638
-    public static function get_paid_product_ids(){
638
+    public static function get_paid_product_ids() {
639 639
 
640 640
         // get all the paid WooCommerce products that has regular
641 641
         // and sale price greater than 0
642 642
         // will be used later to check for course with the id as meta
643
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
643
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
644 644
 
645 645
         // get all the paid WooCommerce products that has regular price
646 646
         // greater than 0 without a sale price
647 647
         // will be used later to check for course with the id as meta
648
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
648
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
649 649
 
650 650
         // combine products ID's with regular and sale price grater than zero and those without
651 651
         // sale but regular price greater than zero
652
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
652
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
653 653
 
654 654
         // if
655
-        if( empty($woocommerce_paid_product_ids) ){
655
+        if (empty($woocommerce_paid_product_ids)) {
656 656
             return array( );
657 657
         }
658 658
         return $woocommerce_paid_product_ids;
@@ -671,20 +671,20 @@  discard block
 block discarded – undo
671 671
      *
672 672
      * @return array
673 673
      */
674
-    public static function get_free_courses(){
674
+    public static function get_free_courses() {
675 675
 
676 676
         $free_course_query_args = Sensei_Course::get_default_query_args();
677
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
677
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
678 678
 
679 679
         // don't show any paid courses
680 680
         $courses = self::get_paid_courses();
681 681
         $ids = array();
682
-        foreach( $courses as $course ){
682
+        foreach ($courses as $course) {
683 683
             $ids[] = $course->ID;
684 684
         }
685
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
685
+        $free_course_query_args['post__not_in'] = $ids;
686 686
 
687
-        return get_posts( $free_course_query_args );
687
+        return get_posts($free_course_query_args);
688 688
 
689 689
     }
690 690
 
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
      * @since 1.9.0
695 695
      * @return array
696 696
      */
697
-    public static function get_paid_courses(){
697
+    public static function get_paid_courses() {
698 698
 
699 699
         $paid_course_query_args = Sensei_Course::get_default_query_args();
700 700
 
701
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
701
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
702 702
 
703
-        return get_posts(  $paid_course_query_args );
703
+        return get_posts($paid_course_query_args);
704 704
     }
705 705
 
706 706
     /**
@@ -715,17 +715,17 @@  discard block
 block discarded – undo
715 715
      * @param int $course_id
716 716
      * @return string $html markup for the button or nothing if user not allowed to buy
717 717
      */
718
-    public static function the_add_to_cart_button_html( $course_id ){
718
+    public static function the_add_to_cart_button_html($course_id) {
719 719
 
720
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
720
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
721 721
             return '';
722 722
         }
723 723
 
724
-        $wc_post_id = self::get_course_product_id( $course_id );
724
+        $wc_post_id = self::get_course_product_id($course_id);
725 725
 
726 726
         // Check if customer purchased the product
727
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
728
-            || empty( $wc_post_id ) ) {
727
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
728
+            || empty($wc_post_id)) {
729 729
 
730 730
             return '';
731 731
 
@@ -733,15 +733,15 @@  discard block
 block discarded – undo
733 733
 
734 734
         // based on simple.php in WC templates/single-product/add-to-cart/
735 735
         // Get the product
736
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
736
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
737 737
 
738 738
         // do not show the button for invalid products, non purchasable products, out
739 739
         // of stock product or if course is already in cart
740
-        if ( ! isset ( $product )
741
-            || ! is_object( $product )
740
+        if ( ! isset ($product)
741
+            || ! is_object($product)
742 742
             || ! $product->is_purchasable()
743 743
             || ! $product->is_in_stock()
744
-            || self::is_course_in_cart( $wc_post_id ) ) {
744
+            || self::is_course_in_cart($wc_post_id)) {
745 745
 
746 746
             return '';
747 747
 
@@ -752,23 +752,23 @@  discard block
 block discarded – undo
752 752
         //
753 753
         ?>
754 754
 
755
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
755
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
756 756
               class="cart"
757 757
               method="post"
758 758
               enctype="multipart/form-data">
759 759
 
760
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
760
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
761 761
 
762 762
             <input type="hidden" name="quantity" value="1" />
763 763
 
764
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
764
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
765 765
 
766 766
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
767
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
767
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
768 768
 
769
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
769
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
770 770
 
771
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
771
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
772 772
 
773 773
                     <?php } ?>
774 774
 
@@ -796,26 +796,26 @@  discard block
 block discarded – undo
796 796
      *
797 797
      * @return string $message
798 798
      */
799
-    public static function alter_no_permissions_message( $message, $post_id ){
799
+    public static function alter_no_permissions_message($message, $post_id) {
800 800
 
801
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
801
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
802 802
             return  $message;
803 803
         }
804 804
 
805
-        $product_id = self::get_course_product_id( $post_id );
805
+        $product_id = self::get_course_product_id($post_id);
806 806
 
807
-        if( ! $product_id
808
-            || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
807
+        if ( ! $product_id
808
+            || ! self::has_customer_bought_product(get_current_user_id(), $product_id)) {
809 809
 
810 810
             return $message;
811 811
 
812 812
         }
813 813
 
814 814
         ob_start();
815
-        self::the_course_no_permissions_message( $post_id );
815
+        self::the_course_no_permissions_message($post_id);
816 816
         $woocommerce_course_no_permissions_message = ob_get_clean();
817 817
 
818
-        return $woocommerce_course_no_permissions_message ;
818
+        return $woocommerce_course_no_permissions_message;
819 819
 
820 820
     }
821 821
     /**
@@ -824,18 +824,18 @@  discard block
 block discarded – undo
824 824
      *
825 825
      * @since 1.9.0
826 826
      */
827
-    public static function the_course_no_permissions_message( $course_id ){
827
+    public static function the_course_no_permissions_message($course_id) {
828 828
 
829 829
         // login link
830
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
831
-	    $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
832
-	    $wc_product_id =  self::get_course_product_id( $course_id );
830
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
831
+	    $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
832
+	    $wc_product_id = self::get_course_product_id($course_id);
833 833
 
834
-	    if ( self::is_product_in_cart( $wc_product_id ) ) {
834
+	    if (self::is_product_in_cart($wc_product_id)) {
835 835
 
836
-		    $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>';
836
+		    $cart_link = '<a href="'.wc_get_checkout_url().'" title="'.__('Checkout', 'woocommerce').'">'.__('checkout', 'woocommerce').'</a>';
837 837
 
838
-		    $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link );
838
+		    $message = sprintf(__('This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei'), $cart_link);
839 839
 		    ?>
840 840
 		    <span class="add-to-cart-login">
841 841
 		            <?php echo $message; ?>
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 
844 844
 		    <?php
845 845
 
846
-	    } elseif ( is_user_logged_in() ) {
846
+	    } elseif (is_user_logged_in()) {
847 847
 
848 848
 		    ?>
849 849
 		    <style>
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 
857 857
 	    } else {
858 858
 
859
-		    $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
859
+		    $message = sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link);
860 860
 	        ?>
861 861
 		        <span class="add-to-cart-login">
862 862
 		            <?php echo $message; ?>
@@ -876,34 +876,34 @@  discard block
 block discarded – undo
876 876
      *
877 877
      * @return bool
878 878
      */
879
-    public static function has_customer_bought_product ( $user_id, $product_id ){
879
+    public static function has_customer_bought_product($user_id, $product_id) {
880 880
 
881
-        $orders = self::get_user_product_orders( $user_id, $product_id );
881
+        $orders = self::get_user_product_orders($user_id, $product_id);
882 882
 
883
-        foreach ( $orders as $order_id ) {
883
+        foreach ($orders as $order_id) {
884 884
 
885
-            $order = new WC_Order( $order_id->ID );
885
+            $order = new WC_Order($order_id->ID);
886 886
 
887 887
             // wc-active is the subscriptions complete status
888
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) )
889
-                || ! ( 0 < sizeof( $order->get_items() ) )  ){
888
+            if ( ! in_array($order->post_status, array('wc-complete', 'wc-processing'))
889
+                || ! (0 < sizeof($order->get_items()))) {
890 890
 
891 891
                 continue;
892 892
 
893 893
             }
894 894
 
895
-            foreach( $order->get_items() as $item ) {
895
+            foreach ($order->get_items() as $item) {
896 896
 
897 897
                 // Check if user has bought product
898
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
898
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
899 899
 
900 900
                     // Check if user has an active subscription for product
901
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
902
-                        $sub_key = wcs_get_subscription( $order );
903
-                        if( $sub_key ) {
904
-                            $sub = wcs_get_subscription( $sub_key );
905
-                            if( $sub && isset( $sub['status'] ) ) {
906
-                                if( 'active' == $sub['status'] ) {
901
+                    if (class_exists('WC_Subscriptions_Manager')) {
902
+                        $sub_key = wcs_get_subscription($order);
903
+                        if ($sub_key) {
904
+                            $sub = wcs_get_subscription($sub_key);
905
+                            if ($sub && isset($sub['status'])) {
906
+                                if ('active' == $sub['status']) {
907 907
                                     return true;
908 908
                                 } else {
909 909
                                     return false;
@@ -935,11 +935,11 @@  discard block
 block discarded – undo
935 935
      * @return string $woocommerce_product_id or false if none exist
936 936
      *
937 937
      */
938
-    public static function get_course_product_id( $course_id ){
938
+    public static function get_course_product_id($course_id) {
939 939
 
940
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
940
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
941 941
 
942
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
942
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
943 943
             return false;
944 944
         }
945 945
 
@@ -955,11 +955,11 @@  discard block
 block discarded – undo
955 955
      * @param array $classes
956 956
      * @return array
957 957
      */
958
-    public static function add_woocommerce_body_class( $classes ){
958
+    public static function add_woocommerce_body_class($classes) {
959 959
 
960
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
960
+        if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) {
961 961
 
962
-            $classes[] ='woocommerce';
962
+            $classes[] = 'woocommerce';
963 963
 
964 964
         }
965 965
 
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
      *
978 978
      * @return  void
979 979
      */
980
-    public static function activate_subscription(  $order ) {
980
+    public static function activate_subscription($order) {
981 981
 
982 982
         $order_user = get_user_by('id', $order->user_id);
983 983
         $user['ID'] = $order_user->ID;
@@ -986,13 +986,13 @@  discard block
 block discarded – undo
986 986
         $user['user_url'] = $order_user->user_url;
987 987
 
988 988
         // Run through each product ordered
989
-        if ( ! sizeof($order->get_items() )>0 ) {
989
+        if ( ! sizeof($order->get_items()) > 0) {
990 990
 
991 991
             return;
992 992
 
993 993
         }
994 994
 
995
-        foreach($order->get_items() as $item) {
995
+        foreach ($order->get_items() as $item) {
996 996
 
997 997
             $product_type = '';
998 998
 
@@ -1007,21 +1007,21 @@  discard block
 block discarded – undo
1007 1007
 
1008 1008
             } // End If Statement
1009 1009
 
1010
-            $_product = self::get_product_object( $item_id, $product_type );
1010
+            $_product = self::get_product_object($item_id, $product_type);
1011 1011
 
1012 1012
             // Get courses that use the WC product
1013 1013
             $courses = array();
1014 1014
 
1015
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1015
+            if ( ! in_array($product_type, self::get_subscription_types())) {
1016 1016
 
1017
-                $courses = Sensei()->course->get_product_courses( $item_id );
1017
+                $courses = Sensei()->course->get_product_courses($item_id);
1018 1018
 
1019 1019
             } // End If Statement
1020 1020
 
1021 1021
             // Loop and add the user to the course.
1022
-            foreach ( $courses as $course_item ){
1022
+            foreach ($courses as $course_item) {
1023 1023
 
1024
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1024
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
1025 1025
 
1026 1026
             } // End For Loop
1027 1027
 
@@ -1039,13 +1039,13 @@  discard block
 block discarded – undo
1039 1039
      *
1040 1040
      * @return  void
1041 1041
      */
1042
-    public static function email_course_details(  $order ){
1042
+    public static function email_course_details($order) {
1043 1043
 
1044 1044
         global $woocommerce;
1045 1045
 
1046 1046
         // exit early if not wc-completed or wc-processing
1047
-        if( 'wc-completed' != $order->post_status
1048
-            && 'wc-processing' != $order->post_status  ) {
1047
+        if ('wc-completed' != $order->post_status
1048
+            && 'wc-processing' != $order->post_status) {
1049 1049
             return;
1050 1050
         }
1051 1051
 
@@ -1053,16 +1053,16 @@  discard block
 block discarded – undo
1053 1053
         $order_id = $order->id;
1054 1054
 
1055 1055
         //If object have items go through them all to find course
1056
-        if ( 0 < sizeof( $order_items ) ) {
1056
+        if (0 < sizeof($order_items)) {
1057 1057
 
1058
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1058
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1059 1059
             $order_contains_courses = false;
1060 1060
 
1061 1061
 
1062
-            foreach ( $order_items as $item ) {
1062
+            foreach ($order_items as $item) {
1063 1063
 
1064 1064
                 $product_type = '';
1065
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1065
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1066 1066
                     // If item has variation_id then its from variation
1067 1067
                     $item_id = $item['variation_id'];
1068 1068
                     $product_type = 'variation';
@@ -1071,9 +1071,9 @@  discard block
 block discarded – undo
1071 1071
                     $item_id = $item['product_id'];
1072 1072
                 } // End If Statement
1073 1073
 
1074
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1074
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1075 1075
 
1076
-                if( $user_id ) {
1076
+                if ($user_id) {
1077 1077
 
1078 1078
                     // Get all courses for product
1079 1079
                     $args = array(
@@ -1088,16 +1088,16 @@  discard block
 block discarded – undo
1088 1088
                         'orderby' => 'menu_order date',
1089 1089
                         'order' => 'ASC',
1090 1090
                     );
1091
-                    $courses = get_posts( $args );
1091
+                    $courses = get_posts($args);
1092 1092
 
1093
-                    if( $courses && count( $courses ) > 0 ) {
1093
+                    if ($courses && count($courses) > 0) {
1094 1094
 
1095
-                        foreach( $courses as $course ) {
1095
+                        foreach ($courses as $course) {
1096 1096
 
1097 1097
                             $title = $course->post_title;
1098
-                            $permalink = get_permalink( $course->ID );
1098
+                            $permalink = get_permalink($course->ID);
1099 1099
                             $order_contains_courses = true;
1100
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1100
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1101 1101
                         }
1102 1102
 
1103 1103
 
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
             } // end for each order item
1109 1109
 
1110 1110
             // Output Course details
1111
-            if( $order_contains_courses ){
1111
+            if ($order_contains_courses) {
1112 1112
 
1113 1113
                 echo $course_details_html;
1114 1114
 
@@ -1126,33 +1126,33 @@  discard block
 block discarded – undo
1126 1126
      * @param   int $order_id WC order ID
1127 1127
      * @return  void
1128 1128
      */
1129
-    public static function complete_order ( $order_id = 0 ) {
1129
+    public static function complete_order($order_id = 0) {
1130 1130
 
1131 1131
         $order_user = array();
1132 1132
 
1133 1133
         // Check for WooCommerce
1134
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1134
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1135 1135
             // Get order object
1136
-            $order = new WC_Order( $order_id );
1136
+            $order = new WC_Order($order_id);
1137 1137
 
1138
-	        if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) {
1138
+	        if ( ! in_array($order->get_status(), array('complete', 'processing'))) {
1139 1139
 
1140 1140
 		        return;
1141 1141
 
1142 1142
 	        }
1143 1143
 
1144
-            $user = get_user_by( 'id', $order->get_user_id() );
1144
+            $user = get_user_by('id', $order->get_user_id());
1145 1145
             $order_user['ID'] = $user->ID;
1146 1146
             $order_user['user_login'] = $user->user_login;
1147 1147
             $order_user['user_email'] = $user->user_email;
1148 1148
             $order_user['user_url'] = $user->user_url;
1149 1149
             // Run through each product ordered
1150
-            if ( 0 < sizeof( $order->get_items() ) ) {
1150
+            if (0 < sizeof($order->get_items())) {
1151 1151
 
1152
-                foreach( $order->get_items() as $item ) {
1152
+                foreach ($order->get_items() as $item) {
1153 1153
 
1154 1154
                     $product_type = '';
1155
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1155
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1156 1156
 
1157 1157
                         $item_id = $item['variation_id'];
1158 1158
                         $product_type = 'variation';
@@ -1163,15 +1163,15 @@  discard block
 block discarded – undo
1163 1163
 
1164 1164
                     } // End If Statement
1165 1165
 
1166
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1166
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1167 1167
 
1168 1168
                     // Get courses that use the WC product
1169
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1169
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1170 1170
 
1171 1171
                     // Loop and update those courses
1172
-                    foreach ( $courses as $course_item ) {
1172
+                    foreach ($courses as $course_item) {
1173 1173
 
1174
-                        $update_course = self::course_update( $course_item->ID, $order_user );
1174
+                        $update_course = self::course_update($course_item->ID, $order_user);
1175 1175
 
1176 1176
                     } // End For Loop
1177 1177
 
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
             } // End If Statement
1181 1181
             // Add meta to indicate that payment has been completed successfully
1182
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1182
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1183 1183
 
1184 1184
         } // End If Statement
1185 1185
 
@@ -1193,34 +1193,34 @@  discard block
 block discarded – undo
1193 1193
      * @param   integer| WC_Order $order_id order ID
1194 1194
      * @return  void
1195 1195
      */
1196
-    public static function cancel_order ( $order_id ) {
1196
+    public static function cancel_order($order_id) {
1197 1197
 
1198 1198
 		// Get order object
1199
-		if( is_object( $order_id ) ){
1199
+		if (is_object($order_id)) {
1200 1200
 
1201 1201
 			$order = $order_id;
1202 1202
 
1203
-		}else{
1203
+		} else {
1204 1204
 
1205
-			$order = new WC_Order( $order_id );
1205
+			$order = new WC_Order($order_id);
1206 1206
 		}
1207 1207
 
1208
-		if ( ! in_array( $order->get_status(), array( 'cancelled', 'refunded' ) ) ) {
1208
+		if ( ! in_array($order->get_status(), array('cancelled', 'refunded'))) {
1209 1209
 
1210 1210
 			return;
1211 1211
 
1212 1212
 		}
1213 1213
 
1214 1214
         // Run through each product ordered
1215
-        if ( 0 < sizeof( $order->get_items() ) ) {
1215
+        if (0 < sizeof($order->get_items())) {
1216 1216
 
1217 1217
             // Get order user
1218
-            $user_id = $order->__get( 'user_id' );
1218
+            $user_id = $order->__get('user_id');
1219 1219
 
1220
-            foreach( $order->get_items() as $item ) {
1220
+            foreach ($order->get_items() as $item) {
1221 1221
 
1222 1222
                 $product_type = '';
1223
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1223
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1224 1224
 
1225 1225
                     $item_id = $item['variation_id'];
1226 1226
                     $product_type = 'variation';
@@ -1231,20 +1231,20 @@  discard block
 block discarded – undo
1231 1231
 
1232 1232
                 } // End If Statement
1233 1233
 
1234
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1234
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1235 1235
 
1236 1236
                 // Get courses that use the WC product
1237 1237
                 $courses = array();
1238
-                $courses = Sensei()->course->get_product_courses( $item_id );
1238
+                $courses = Sensei()->course->get_product_courses($item_id);
1239 1239
 
1240 1240
                 // Loop and update those courses
1241
-                foreach ($courses as $course_item){
1241
+                foreach ($courses as $course_item) {
1242 1242
 
1243
-	                if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){
1243
+	                if (self::has_customer_bought_product($user_id, $course_item->ID)) {
1244 1244
 		                continue;
1245 1245
 	                }
1246 1246
                     // Check and Remove course from courses user meta
1247
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1247
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1248 1248
 
1249 1249
                 } // End For Loop
1250 1250
 
@@ -1265,30 +1265,30 @@  discard block
 block discarded – undo
1265 1265
      * @param   string  $product_type  '' or 'variation'
1266 1266
      * @return   WC_Product $wc_product_object
1267 1267
      */
1268
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1268
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1269 1269
 
1270 1270
         $wc_product_object = false;
1271
-        if ( 0 < intval( $wc_product_id ) ) {
1271
+        if (0 < intval($wc_product_id)) {
1272 1272
 
1273 1273
             // Get the product
1274
-            if ( function_exists( 'wc_get_product' ) ) {
1274
+            if (function_exists('wc_get_product')) {
1275 1275
 
1276
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1276
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1277 1277
 
1278
-            } elseif ( function_exists( 'get_product' ) ) {
1278
+            } elseif (function_exists('get_product')) {
1279 1279
 
1280
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1280
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1281 1281
 
1282 1282
             } else {
1283 1283
 
1284 1284
                 // Pre WC 2.0
1285
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1285
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1286 1286
 
1287
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1287
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1288 1288
 
1289 1289
                 } else {
1290 1290
 
1291
-                    $wc_product_object = new WC_Product( $wc_product_id );
1291
+                    $wc_product_object = new WC_Product($wc_product_id);
1292 1292
 
1293 1293
                 } // End If Statement
1294 1294
 
@@ -1311,19 +1311,19 @@  discard block
 block discarded – undo
1311 1311
      *
1312 1312
      * @return bool|int
1313 1313
      */
1314
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1314
+    public static function course_update($course_id = 0, $order_user = array()) {
1315 1315
 
1316 1316
         global $current_user;
1317 1317
 
1318
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1318
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1319 1319
 
1320 1320
         $data_update = false;
1321 1321
 
1322 1322
         // Get the product ID
1323
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1323
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1324 1324
 
1325 1325
         // Check if in the admin
1326
-        if ( is_admin() ) {
1326
+        if (is_admin()) {
1327 1327
 
1328 1328
             $user_login = $order_user['user_login'];
1329 1329
             $user_email = $order_user['user_email'];
@@ -1340,28 +1340,28 @@  discard block
 block discarded – undo
1340 1340
         } // End If Statement
1341 1341
 
1342 1342
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1343
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1344
-        if( 0 < absint( $course_prerequisite_id ) ) {
1343
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1344
+        if (0 < absint($course_prerequisite_id)) {
1345 1345
 
1346
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1347
-            if ( ! $prereq_course_complete ) {
1346
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1347
+            if ( ! $prereq_course_complete) {
1348 1348
 
1349 1349
                 // Remove all course user meta
1350
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1350
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1351 1351
 
1352 1352
             }
1353 1353
         }
1354 1354
 
1355
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1355
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1356 1356
 
1357 1357
         if ( ! $is_user_taking_course
1358 1358
             && Sensei_WC::is_woocommerce_active()
1359 1359
             && 0 < $wc_post_id
1360
-            && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) {
1360
+            && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id)) {
1361 1361
 
1362
-	            $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) );
1362
+	            $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1363 1363
 
1364
-	            if ( true == $activity_logged ) {
1364
+	            if (true == $activity_logged) {
1365 1365
 
1366 1366
 		            $is_user_taking_course = true;
1367 1367
 
@@ -1383,14 +1383,14 @@  discard block
 block discarded – undo
1383 1383
      *
1384 1384
      * @return boolean                 Modified guest checkout setting
1385 1385
      */
1386
-    public static function disable_guest_checkout( $guest_checkout ) {
1386
+    public static function disable_guest_checkout($guest_checkout) {
1387 1387
 
1388
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1388
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1389 1389
 
1390
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1390
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1391 1391
 
1392
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1393
-                    if( isset( $product['product_id'] ) ) {
1392
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1393
+                    if (isset($product['product_id'])) {
1394 1394
 
1395 1395
                         $args = array(
1396 1396
                             'posts_per_page' => -1,
@@ -1403,11 +1403,11 @@  discard block
 block discarded – undo
1403 1403
                             )
1404 1404
                         );
1405 1405
 
1406
-                        $posts = get_posts( $args );
1406
+                        $posts = get_posts($args);
1407 1407
 
1408
-                        if( $posts && count( $posts ) > 0 ) {
1408
+                        if ($posts && count($posts) > 0) {
1409 1409
 
1410
-                            foreach( $posts as $course ) {
1410
+                            foreach ($posts as $course) {
1411 1411
                                 $guest_checkout = '';
1412 1412
                                 break;
1413 1413
 
@@ -1436,23 +1436,23 @@  discard block
 block discarded – undo
1436 1436
      *
1437 1437
      * @return string
1438 1438
      **/
1439
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1439
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1440 1440
 
1441
-        $order = new WC_Order( $order_id );
1441
+        $order = new WC_Order($order_id);
1442 1442
 
1443
-        if ( ! isset ( $order ) ) return '';
1443
+        if ( ! isset ($order)) return '';
1444 1444
 
1445
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1445
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1446 1446
 
1447 1447
             $virtual_order = true;
1448 1448
 
1449
-            if ( count( $order->get_items() ) > 0 ) {
1449
+            if (count($order->get_items()) > 0) {
1450 1450
 
1451
-                foreach( $order->get_items() as $item ) {
1451
+                foreach ($order->get_items() as $item) {
1452 1452
 
1453
-                    if ( $item['product_id'] > 0 ) {
1454
-                        $_product = $order->get_product_from_item( $item );
1455
-                        if ( ! $_product->is_virtual() ) {
1453
+                    if ($item['product_id'] > 0) {
1454
+                        $_product = $order->get_product_from_item($item);
1455
+                        if ( ! $_product->is_virtual()) {
1456 1456
 
1457 1457
                             $virtual_order = false;
1458 1458
                             break;
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
             } // End If Statement
1467 1467
 
1468 1468
             // virtual order, mark as completed
1469
-            if ( $virtual_order ) {
1469
+            if ($virtual_order) {
1470 1470
 
1471 1471
                 return 'completed';
1472 1472
 
@@ -1489,14 +1489,14 @@  discard block
 block discarded – undo
1489 1489
      * @param  integer $user_id
1490 1490
      * @return boolean $user_access_permission
1491 1491
      */
1492
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1492
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1493 1493
 
1494 1494
         global $post;
1495 1495
 
1496 1496
         // ignore the current case if the following conditions are met
1497
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1498
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1499
-            || ! wcs_user_has_subscription( $user_id) ){
1497
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1498
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1499
+            || ! wcs_user_has_subscription($user_id)) {
1500 1500
 
1501 1501
             return $user_access_permission;
1502 1502
 
@@ -1506,25 +1506,25 @@  discard block
 block discarded – undo
1506 1506
         // is the subscription on the the current course?
1507 1507
 
1508 1508
         $course_id = 0;
1509
-        if ( 'course' == $post->post_type ){
1509
+        if ('course' == $post->post_type) {
1510 1510
 
1511 1511
             $course_id = $post->ID;
1512 1512
 
1513
-        } elseif ( 'lesson' == $post->post_type ) {
1513
+        } elseif ('lesson' == $post->post_type) {
1514 1514
 
1515
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1515
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1516 1516
 
1517 1517
         } else {
1518 1518
 
1519
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1520
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1519
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1520
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1521 1521
 
1522 1522
         }
1523 1523
 
1524 1524
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1525
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1526
-        $product = wc_get_product( $product_id );
1527
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1525
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1526
+        $product = wc_get_product($product_id);
1527
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1528 1528
 
1529 1529
             return $user_access_permission;
1530 1530
 
@@ -1532,19 +1532,19 @@  discard block
 block discarded – undo
1532 1532
 
1533 1533
         // give access if user has active subscription on the product otherwise restrict it.
1534 1534
         // also check if the user was added to the course directly after the subscription started.
1535
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1536
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1537
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1535
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1536
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1537
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1538 1538
 
1539 1539
             $user_access_permission = true;
1540 1540
 
1541
-        }else{
1541
+        } else {
1542 1542
 
1543 1543
             $user_access_permission = false;
1544 1544
             // do not show the WC permissions message
1545
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1546
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1547
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1545
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1546
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1547
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1548 1548
         }
1549 1549
 
1550 1550
         return $user_access_permission;
@@ -1557,9 +1557,9 @@  discard block
 block discarded – undo
1557 1557
      * @since 1.9.0
1558 1558
      * @return array
1559 1559
      */
1560
-    public static function get_subscription_types(){
1560
+    public static function get_subscription_types() {
1561 1561
 
1562
-        return array( 'subscription','subscription_variation','variable-subscription' );
1562
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1563 1563
 
1564 1564
     }
1565 1565
 
@@ -1579,15 +1579,15 @@  discard block
 block discarded – undo
1579 1579
      *
1580 1580
      * @return bool
1581 1581
      */
1582
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1582
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1583 1583
 
1584 1584
         $course_start_date = '';
1585 1585
         $subscription_start_date = '';
1586
-        $is_a_subscription ='';
1586
+        $is_a_subscription = '';
1587 1587
         $was_user_added_without_subscription = true;
1588 1588
 
1589 1589
         // if user is not on the course they were not added
1590
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1590
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1591 1591
 
1592 1592
             return false;
1593 1593
 
@@ -1596,34 +1596,34 @@  discard block
 block discarded – undo
1596 1596
         // if user doesn't have a subscription and is taking the course
1597 1597
         // they were added manually
1598 1598
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1599
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1599
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1600 1600
 
1601 1601
             return true;
1602 1602
 
1603 1603
         }
1604 1604
 
1605
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1605
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1606 1606
 
1607 1607
         // comparing dates setup data
1608
-        $course_start_date = date_create( $course_status->comment_date );
1609
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1608
+        $course_start_date = date_create($course_status->comment_date);
1609
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1610 1610
 
1611 1611
         // comparing every subscription
1612
-        foreach( $subscriptions as $subscription ){
1612
+        foreach ($subscriptions as $subscription) {
1613 1613
 
1614 1614
             // for the following statuses we know the user was not added
1615 1615
             // manually
1616 1616
             $status = $subscription->get_status();
1617
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1617
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1618 1618
 
1619 1619
                 continue;
1620 1620
 
1621 1621
             }
1622 1622
 
1623
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1623
+            $current_subscription_start_date = date_create($subscription->modified_date);
1624 1624
 
1625 1625
             // is the last updated subscription date newer than course start date
1626
-            if (  $current_subscription_start_date > $course_start_date   ) {
1626
+            if ($current_subscription_start_date > $course_start_date) {
1627 1627
 
1628 1628
                 return false;
1629 1629
 
@@ -1642,15 +1642,15 @@  discard block
 block discarded – undo
1642 1642
 	 *
1643 1643
 	 * @return array $orders
1644 1644
 	 */
1645
-	public static function get_user_product_orders( $user_id =  0, $product_id ) {
1645
+	public static function get_user_product_orders($user_id = 0, $product_id) {
1646 1646
 
1647
-		return get_posts( array(
1647
+		return get_posts(array(
1648 1648
 			'numberposts' => -1,
1649 1649
 			'post_type' => 'shop_order',
1650 1650
 			'meta_key'    => '_customer_user',
1651
-			'meta_value'  => intval( $user_id ),
1652
-			'post_status' => array( 'wc-complete','wc-processing' ),
1653
-		) );
1651
+			'meta_value'  => intval($user_id),
1652
+			'post_status' => array('wc-complete', 'wc-processing'),
1653
+		));
1654 1654
 
1655 1655
 	}
1656 1656
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// security check, don't load file outside WP
3 6
 
4 7
 /**
5 8
  * Sensei WooCommerce class
@@ -1200,7 +1203,7 @@  discard block
 block discarded – undo
1200 1203
 
1201 1204
 			$order = $order_id;
1202 1205
 
1203
-		}else{
1206
+		} else{
1204 1207
 
1205 1208
 			$order = new WC_Order( $order_id );
1206 1209
 		}
@@ -1315,7 +1318,9 @@  discard block
 block discarded – undo
1315 1318
 
1316 1319
         global $current_user;
1317 1320
 
1318
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1321
+        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) {
1322
+        	return false;
1323
+        }
1319 1324
 
1320 1325
         $data_update = false;
1321 1326
 
@@ -1440,7 +1445,9 @@  discard block
 block discarded – undo
1440 1445
 
1441 1446
         $order = new WC_Order( $order_id );
1442 1447
 
1443
-        if ( ! isset ( $order ) ) return '';
1448
+        if ( ! isset ( $order ) ) {
1449
+        	return '';
1450
+        }
1444 1451
 
1445 1452
         if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1446 1453
 
@@ -1538,7 +1545,7 @@  discard block
 block discarded – undo
1538 1545
 
1539 1546
             $user_access_permission = true;
1540 1547
 
1541
-        }else{
1548
+        } else{
1542 1549
 
1543 1550
             $user_access_permission = false;
1544 1551
             // do not show the WC permissions message
Please login to merge, or discard this patch.
includes/hooks/woocommerce.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
  * show the WooCommerce course filter links above the courses
8 8
  * @since 1.9.0
9 9
  */
10
-add_filter( 'sensei_archive_course_filter_by_options', array( 'Sensei_WC', 'add_course_archive_wc_filter_links' ) );
10
+add_filter('sensei_archive_course_filter_by_options', array('Sensei_WC', 'add_course_archive_wc_filter_links'));
11 11
 
12 12
 /**
13 13
  * filter the queries for paid and free course based on the users selection.
14 14
  * @since 1.9.0
15 15
  */
16
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_free'));
17
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_paid'));
16
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_free'));
17
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_paid'));
18 18
 
19 19
 /**
20 20
  * Add woocommerce action above single course the action
21 21
  * @since 1.9.0
22 22
  */
23
-add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action') ,50) ;
23
+add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action'), 50);
24 24
 
25 25
 
26 26
 /******************************
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * Single Lesson Hooks
29 29
  *
30 30
  ******************************/
31
-add_filter( 'sensei_can_user_view_lesson', array( 'Sensei_WC','alter_can_user_view_lesson' ), 20, 3 );
31
+add_filter('sensei_can_user_view_lesson', array('Sensei_WC', 'alter_can_user_view_lesson'), 20, 3);
32 32
 
33 33
 /******************************
34 34
  *
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *
37 37
  ******************************/
38 38
 // add a notice on the checkout page to tell users about the course they've purchase
39
-add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
39
+add_action('template_redirect', array('Sensei_WC', 'course_link_from_order'));
40 40
 
41 41
 /******************************
42 42
  *
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
  ******************************/
46 46
 //@since 1.9.0
47 47
 //show a notice if the user has already added the current course to their cart
48
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_WC', 'course_in_cart_message' ), 20 );
48
+add_action('sensei_single_course_content_inside_before', array('Sensei_WC', 'course_in_cart_message'), 20);
49 49
 
50 50
 /******************************
51 51
  *
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
  ******************************/
55 55
 //@since 1.9.0
56 56
 // alter the no permissions message to show the woocommerce message instead
57
-add_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
57
+add_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
58 58
 
59 59
 //@since 1.9.0
60 60
 // add the add to cart button for a valid purchasable course
61
-add_action( 'sensei_no_permissions_inside_before_content', array( 'Sensei_WC', 'the_add_to_cart_button_html' ), 20, 1);
61
+add_action('sensei_no_permissions_inside_before_content', array('Sensei_WC', 'the_add_to_cart_button_html'), 20, 1);
62 62
 
63 63
 // @since 1.9.0
64 64
 // add  woocommerce class to the the no permission body class to ensure WooCommerce elements are styled
65
-add_filter( 'body_class', array( 'Sensei_WC', 'add_woocommerce_body_class' ), 20, 1);
65
+add_filter('body_class', array('Sensei_WC', 'add_woocommerce_body_class'), 20, 1);
66 66
 
67 67
 
68 68
 /************************************
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
  *
72 72
  ************************************/
73 73
 // Add Email link to course orders
74
-add_action( 'woocommerce_email_after_order_table', array( 'Sensei_WC', 'email_course_details' ), 10, 1 );
74
+add_action('woocommerce_email_after_order_table', array('Sensei_WC', 'email_course_details'), 10, 1);
75 75
 
76 76
 /************************************
77 77
  *
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
  ************************************/
81 81
 //add_action( 'woocommerce_payment_complete',                 array( 'Sensei_WC', 'complete_order' ) );
82 82
 //add_action( 'woocommerce_thankyou' ,                        array( 'Sensei_WC', 'complete_order' ) );
83
-add_action( 'woocommerce_delete_shop_order_transients',           array( 'Sensei_WC', 'complete_order' ) );
84
-add_action( 'woocommerce_delete_shop_order_transients',            array( 'Sensei_WC', 'cancel_order' ) );
83
+add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'complete_order'));
84
+add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'cancel_order'));
85 85
 // Disable guest checkout if a course is in the cart as we need a valid user to store data for
86
-add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( 'Sensei_WC', 'disable_guest_checkout' ) );
86
+add_filter('pre_option_woocommerce_enable_guest_checkout', array('Sensei_WC', 'disable_guest_checkout'));
87 87
 // Mark orders with virtual products as complete rather then stay processing
88
-add_filter( 'woocommerce_payment_complete_order_status',    array( 'Sensei_WC', 'virtual_order_payment_complete' ), 10, 2 );
88
+add_filter('woocommerce_payment_complete_order_status', array('Sensei_WC', 'virtual_order_payment_complete'), 10, 2);
89 89
 
90 90
 /************************************
91 91
  *
92 92
  * WooCommerce Subscriptions
93 93
  *
94 94
  ************************************/
95
-add_action( 'woocommerce_subscription_status_pending_to_active', array( 'Sensei_WC', 'activate_subscription' ), 50, 3 );
95
+add_action('woocommerce_subscription_status_pending_to_active', array('Sensei_WC', 'activate_subscription'), 50, 3);
96 96
 // filter the user permission of the subscription is not valid
97
-add_filter( 'sensei_access_permissions',               array( 'Sensei_WC', 'get_subscription_permission' ), 10, 2 );
97
+add_filter('sensei_access_permissions', array('Sensei_WC', 'get_subscription_permission'), 10, 2);
Please login to merge, or discard this patch.