Completed
Pull Request — master (#1270)
by
unknown
05:01
created
includes/class-sensei-wc.php 1 patch
Spacing   +287 added lines, -287 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,28 +260,28 @@  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
-	    if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id ) ){
266
+	    if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)) {
267 267
 		    return true;
268 268
 	    }
269 269
 
270 270
         // check if the course has a valid product attached to it
271 271
         // which the user should have purchased if they want to access
272 272
         // the current lesson
273
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
274
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
273
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
274
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
275 275
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
276
-        if( isset ($product) && is_object($product) ){
276
+        if (isset ($product) && is_object($product)) {
277 277
 
278 278
             // valid product found
279
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
279
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
280 280
 
281 281
             // product has a successful order so this user may access the content
282 282
             // this function may only return false or the default
283 283
             // returning true may override other negatives which we don't want
284
-            if( ! $order_id ){
284
+            if ( ! $order_id) {
285 285
 
286 286
                 return false;
287 287
 
@@ -304,23 +304,23 @@  discard block
 block discarded – undo
304 304
      */
305 305
     public static function course_link_from_order( ) {
306 306
 
307
-        if( ! is_order_received_page() ){
307
+        if ( ! is_order_received_page()) {
308 308
             return;
309 309
         }
310 310
 
311
-        $order_id = get_query_var( 'order-received' );
312
-		$order = new WC_Order( $order_id );
311
+        $order_id = get_query_var('order-received');
312
+		$order = new WC_Order($order_id);
313 313
 
314 314
 		// exit early if not wc-completed or wc-processing
315
-		if( 'wc-completed' != $order->post_status
316
-            && 'wc-processing' != $order->post_status  ) {
315
+		if ('wc-completed' != $order->post_status
316
+            && 'wc-processing' != $order->post_status) {
317 317
             return;
318 318
         }
319 319
 
320 320
         $course_links = array(); // store the for links for courses purchased
321
-		foreach ( $order->get_items() as $item ) {
321
+		foreach ($order->get_items() as $item) {
322 322
 
323
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
323
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
324 324
 
325 325
                 // If item has variation_id then its a variation of the product
326 326
                 $item_id = $item['variation_id'];
@@ -332,28 +332,28 @@  discard block
 block discarded – undo
332 332
 
333 333
             } // End If Statement
334 334
 
335
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
335
+            $user_id = get_post_meta($order->id, '_customer_user', true);
336 336
 
337
-            if( $user_id ) {
337
+            if ($user_id) {
338 338
 
339 339
                 // Get all courses for product
340 340
                 $args = Sensei_Course::get_default_query_args();
341
-                $args['meta_query'] = array( array(
341
+                $args['meta_query'] = array(array(
342 342
                             'key' => '_course_woocommerce_product',
343 343
                             'value' => $item_id
344
-                        ) );
344
+                        ));
345 345
                 $args['orderby'] = 'menu_order date';
346 346
                 $args['order'] = 'ASC';
347 347
 
348 348
                 // loop through courses
349
-                $courses = get_posts( $args );
350
-                if( $courses && count( $courses ) > 0 ) {
349
+                $courses = get_posts($args);
350
+                if ($courses && count($courses) > 0) {
351 351
 
352
-                    foreach( $courses as $course ) {
352
+                    foreach ($courses as $course) {
353 353
 
354 354
                         $title = $course->post_title;
355
-                        $permalink = get_permalink( $course->ID );
356
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
355
+                        $permalink = get_permalink($course->ID);
356
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
357 357
 
358 358
                     } // end for each
359 359
 
@@ -364,24 +364,24 @@  discard block
 block discarded – undo
364 364
         }// end loop through orders
365 365
 
366 366
         // add the courses to the WooCommerce notice
367
-        if( ! empty( $course_links) ){
367
+        if ( ! empty($course_links)) {
368 368
 
369 369
             $courses_html = _nx(
370 370
                 'You have purchased the following course:',
371 371
                 'You have purchased the following courses:',
372
-                count( $course_links ),
372
+                count($course_links),
373 373
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
374 374
             );
375 375
 
376
-            foreach( $course_links as $link ){
376
+            foreach ($course_links as $link) {
377 377
 
378
-                $courses_html .= '<li>' . $link . '</li>';
378
+                $courses_html .= '<li>'.$link.'</li>';
379 379
 
380 380
             }
381 381
 
382 382
             $courses_html .= ' </ul>';
383 383
 
384
-            wc_add_notice( $courses_html, 'success' );
384
+            wc_add_notice($courses_html, 'success');
385 385
         }
386 386
 
387 387
 	} // end course_link_order_form
@@ -394,20 +394,20 @@  discard block
 block discarded – undo
394 394
      *
395 395
      * @since 1.9.0
396 396
      */
397
-    public static function course_in_cart_message(){
397
+    public static function course_in_cart_message() {
398 398
 
399 399
         global $post;
400 400
 
401
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
401
+        if (self::is_course_in_cart($post->ID)) { ?>
402 402
 
403 403
             <div class="sensei-message info">
404 404
                 <?php
405 405
 
406
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
407
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
408
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
406
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
407
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
408
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
409 409
 
410
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
410
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
411 411
 
412 412
                 ?>
413 413
             </div>
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
      * @param $course_id
422 422
      * @return bool
423 423
      */
424
-    public static function is_course_in_cart( $course_id ){
424
+    public static function is_course_in_cart($course_id) {
425 425
 
426
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
427
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
426
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
427
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
428 428
 
429
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
429
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
430 430
 
431
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
431
+            if (self::is_product_in_cart($wc_post_id)) {
432 432
 
433 433
                 return true;
434 434
 
@@ -446,20 +446,20 @@  discard block
 block discarded – undo
446 446
      * @param $product_id
447 447
      * @return bool
448 448
      */
449
-    public static function is_product_in_cart( $product_id ){
449
+    public static function is_product_in_cart($product_id) {
450 450
 
451
-        if ( 0 < $product_id ) {
451
+        if (0 < $product_id) {
452 452
 
453
-            $product = wc_get_product( $product_id );
453
+            $product = wc_get_product($product_id);
454 454
 
455 455
             $parent_id = '';
456
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
456
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
457 457
                 $wc_product_id = $product->parent->id;
458 458
             }
459
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
459
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
460 460
 
461 461
                 $cart_product = $values['data'];
462
-                if( $product_id == $cart_product->id ) {
462
+                if ($product_id == $cart_product->id) {
463 463
 
464 464
                     return true;
465 465
 
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
      *  @type int $wp_post_id
482 482
      * }
483 483
      */
484
-    public static function get_free_product_ids(){
484
+    public static function get_free_product_ids() {
485 485
 
486
-        return  get_posts( array(
486
+        return  get_posts(array(
487 487
             'post_type' => 'product',
488 488
             'posts_per_page' => '1000',
489 489
             'fields' => 'ids',
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      * @since 1.9.0
509 509
      * @return array $wp_meta_query_param
510 510
      */
511
-    public static function get_free_courses_meta_query_args(){
511
+    public static function get_free_courses_meta_query_args() {
512 512
 
513 513
         return array(
514 514
             'relation' => 'OR',
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
      * @since 1.9.0
533 533
      * @return array $wp_query_meta_query_args_param
534 534
      */
535
-    public static function get_paid_courses_meta_query_args(){
535
+    public static function get_paid_courses_meta_query_args() {
536 536
 
537 537
         $paid_product_ids = self::get_paid_product_ids();
538 538
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
                 'key'     => '_course_woocommerce_product',
542 542
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
543 543
                 // query
544
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
544
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
545 545
                 'compare' => 'IN',
546 546
             ),
547 547
         );
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
      * @since 1.9.0
556 556
      * @return array $product_query_args
557 557
      */
558
-    public static function get_paid_products_on_sale_query_args(){
558
+    public static function get_paid_products_on_sale_query_args() {
559 559
 
560 560
         $args = array(
561 561
                    'post_type' 		=> 'product',
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
                    'suppress_filters' 	=> 0
566 566
         );
567 567
 
568
-        $args[ 'fields' ]     = 'ids';
568
+        $args['fields']     = 'ids';
569 569
 
570
-        $args[ 'meta_query' ] = array(
570
+        $args['meta_query'] = array(
571 571
             'relation' => 'AND',
572 572
             array(
573 573
                 'key'=> '_regular_price',
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
      *
595 595
      * @return array
596 596
      */
597
-    public static function get_paid_products_not_on_sale_query_args(){
597
+    public static function get_paid_products_not_on_sale_query_args() {
598 598
 
599 599
         $args = array(
600 600
             'post_type' 		=> 'product',
@@ -604,8 +604,8 @@  discard block
 block discarded – undo
604 604
             'suppress_filters' 	=> 0
605 605
         );
606 606
 
607
-        $args[ 'fields' ]     = 'ids';
608
-        $args[ 'meta_query' ] = array(
607
+        $args['fields']     = 'ids';
608
+        $args['meta_query'] = array(
609 609
             'relation' => 'AND',
610 610
             array(
611 611
                 'key'=> '_regular_price',
@@ -631,24 +631,24 @@  discard block
 block discarded – undo
631 631
      *
632 632
      * @return array $woocommerce_paid_product_ids
633 633
      */
634
-    public static function get_paid_product_ids(){
634
+    public static function get_paid_product_ids() {
635 635
 
636 636
         // get all the paid WooCommerce products that has regular
637 637
         // and sale price greater than 0
638 638
         // will be used later to check for course with the id as meta
639
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
639
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
640 640
 
641 641
         // get all the paid WooCommerce products that has regular price
642 642
         // greater than 0 without a sale price
643 643
         // will be used later to check for course with the id as meta
644
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
644
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
645 645
 
646 646
         // combine products ID's with regular and sale price grater than zero and those without
647 647
         // sale but regular price greater than zero
648
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
648
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
649 649
 
650 650
         // if
651
-        if( empty($woocommerce_paid_product_ids) ){
651
+        if (empty($woocommerce_paid_product_ids)) {
652 652
             return array( );
653 653
         }
654 654
         return $woocommerce_paid_product_ids;
@@ -667,20 +667,20 @@  discard block
 block discarded – undo
667 667
      *
668 668
      * @return array
669 669
      */
670
-    public static function get_free_courses(){
670
+    public static function get_free_courses() {
671 671
 
672 672
         $free_course_query_args = Sensei_Course::get_default_query_args();
673
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
673
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
674 674
 
675 675
         // don't show any paid courses
676 676
         $courses = self::get_paid_courses();
677 677
         $ids = array();
678
-        foreach( $courses as $course ){
678
+        foreach ($courses as $course) {
679 679
             $ids[] = $course->ID;
680 680
         }
681
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
681
+        $free_course_query_args['post__not_in'] = $ids;
682 682
 
683
-        return get_posts( $free_course_query_args );
683
+        return get_posts($free_course_query_args);
684 684
 
685 685
     }
686 686
 
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
      * @since 1.9.0
691 691
      * @return array
692 692
      */
693
-    public static function get_paid_courses(){
693
+    public static function get_paid_courses() {
694 694
 
695 695
         $paid_course_query_args = Sensei_Course::get_default_query_args();
696 696
 
697
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
697
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
698 698
 
699
-        return get_posts(  $paid_course_query_args );
699
+        return get_posts($paid_course_query_args);
700 700
     }
701 701
 
702 702
     /**
@@ -711,17 +711,17 @@  discard block
 block discarded – undo
711 711
      * @param int $course_id
712 712
      * @return string $html markup for the button or nothing if user not allowed to buy
713 713
      */
714
-    public static function the_add_to_cart_button_html( $course_id ){
714
+    public static function the_add_to_cart_button_html($course_id) {
715 715
 
716
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
716
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
717 717
             return '';
718 718
         }
719 719
 
720
-        $wc_post_id = self::get_course_product_id( $course_id );
720
+        $wc_post_id = self::get_course_product_id($course_id);
721 721
 
722 722
         // Check if customer purchased the product
723
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
724
-            || empty( $wc_post_id ) ) {
723
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
724
+            || empty($wc_post_id)) {
725 725
 
726 726
             return '';
727 727
 
@@ -729,15 +729,15 @@  discard block
 block discarded – undo
729 729
 
730 730
         // based on simple.php in WC templates/single-product/add-to-cart/
731 731
         // Get the product
732
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
732
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
733 733
 
734 734
         // do not show the button for invalid products, non purchasable products, out
735 735
         // of stock product or if course is already in cart
736
-        if ( ! isset ( $product )
737
-            || ! is_object( $product )
736
+        if ( ! isset ($product)
737
+            || ! is_object($product)
738 738
             || ! $product->is_purchasable()
739 739
             || ! $product->is_in_stock()
740
-            || self::is_course_in_cart( $wc_post_id ) ) {
740
+            || self::is_course_in_cart($wc_post_id)) {
741 741
 
742 742
             return '';
743 743
 
@@ -748,23 +748,23 @@  discard block
 block discarded – undo
748 748
         //
749 749
         ?>
750 750
 
751
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
751
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
752 752
               class="cart"
753 753
               method="post"
754 754
               enctype="multipart/form-data">
755 755
 
756
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
756
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
757 757
 
758 758
             <input type="hidden" name="quantity" value="1" />
759 759
 
760
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
760
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
761 761
 
762 762
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
763
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
763
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
764 764
 
765
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
765
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
766 766
 
767
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
767
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
768 768
 
769 769
                     <?php } ?>
770 770
 
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
             <?php } ?>
774 774
 
775 775
             <button type="submit" class="single_add_to_cart_button button alt">
776
-                <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?>
776
+                <?php $button_text = $product->get_price_html().' - '.__('Purchase this Course', 'woothemes-sensei'); ?>
777 777
                 <?php
778 778
                 /**
779 779
                  * Filter Add to Cart button text
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
                  *
783 783
                  * @param string $button_text
784 784
                  */
785
-                echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text );
785
+                echo apply_filters('sensei_wc_single_add_to_cart_button_text', $button_text);
786 786
                 ?>
787 787
             </button>
788 788
 
@@ -802,26 +802,26 @@  discard block
 block discarded – undo
802 802
      *
803 803
      * @return string $message
804 804
      */
805
-    public static function alter_no_permissions_message( $message, $post_id ){
805
+    public static function alter_no_permissions_message($message, $post_id) {
806 806
 
807
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
807
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
808 808
             return  $message;
809 809
         }
810 810
 
811
-        $product_id = self::get_course_product_id( $post_id );
811
+        $product_id = self::get_course_product_id($post_id);
812 812
 
813
-        if( ! $product_id
814
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
813
+        if ( ! $product_id
814
+            || self::has_customer_bought_product(get_current_user_id(), $product_id)) {
815 815
 
816 816
             return $message;
817 817
 
818 818
         }
819 819
 
820 820
         ob_start();
821
-        self::the_course_no_permissions_message( $post_id );
821
+        self::the_course_no_permissions_message($post_id);
822 822
         $woocommerce_course_no_permissions_message = ob_get_clean();
823 823
 
824
-        return $woocommerce_course_no_permissions_message ;
824
+        return $woocommerce_course_no_permissions_message;
825 825
 
826 826
     }
827 827
     /**
@@ -830,16 +830,16 @@  discard block
 block discarded – undo
830 830
      *
831 831
      * @since 1.9.0
832 832
      */
833
-    public static function the_course_no_permissions_message( $course_id ){
833
+    public static function the_course_no_permissions_message($course_id) {
834 834
 
835 835
         // login link
836
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
837
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
836
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
837
+        $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
838 838
 
839 839
         ?>
840 840
 
841 841
         <span class="add-to-cart-login">
842
-            <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
842
+            <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?>
843 843
         </span>
844 844
 
845 845
     <?php }
@@ -854,45 +854,45 @@  discard block
 block discarded – undo
854 854
      *
855 855
      * @return bool
856 856
      */
857
-    public static function has_customer_bought_product ( $user_id, $product_id ){
857
+    public static function has_customer_bought_product($user_id, $product_id) {
858 858
 
859
-        $orders = get_posts( array(
859
+        $orders = get_posts(array(
860 860
             'numberposts' => -1,
861 861
             'post_type' => 'shope_order',
862 862
             'meta_key'    => '_customer_user',
863
-            'meta_value'  => intval( $user_id ),
864
-            'post_status' => array( 'wc-complete','wc-processing' ),
865
-        ) );
863
+            'meta_value'  => intval($user_id),
864
+            'post_status' => array('wc-complete', 'wc-processing'),
865
+        ));
866 866
 
867
-        foreach ( $orders as $order_id ) {
867
+        foreach ($orders as $order_id) {
868 868
 
869
-            $order = new WC_Order( $order_id->ID );
869
+            $order = new WC_Order($order_id->ID);
870 870
 
871 871
             // wc-active is the subscriptions complete status
872
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){
872
+            if ( ! in_array($order->post_status, array('wc-complete', 'wc-processing'))) {
873 873
 
874 874
                 continue;
875 875
 
876 876
             }
877 877
 
878
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
878
+            if ( ! (0 < sizeof($order->get_items()))) {
879 879
 
880 880
                 continue;
881 881
 
882 882
             }
883 883
 
884
-            foreach( $order->get_items() as $item ) {
884
+            foreach ($order->get_items() as $item) {
885 885
 
886 886
                 // Check if user has bought product
887
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
887
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
888 888
 
889 889
                     // Check if user has an active subscription for product
890
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
891
-                        $sub_key = wcs_get_subscription( $order );
892
-                        if( $sub_key ) {
893
-                            $sub = wcs_get_subscription( $sub_key );
894
-                            if( $sub && isset( $sub['status'] ) ) {
895
-                                if( 'active' == $sub['status'] ) {
890
+                    if (class_exists('WC_Subscriptions_Manager')) {
891
+                        $sub_key = wcs_get_subscription($order);
892
+                        if ($sub_key) {
893
+                            $sub = wcs_get_subscription($sub_key);
894
+                            if ($sub && isset($sub['status'])) {
895
+                                if ('active' == $sub['status']) {
896 896
                                     return true;
897 897
                                 } else {
898 898
                                     return false;
@@ -921,11 +921,11 @@  discard block
 block discarded – undo
921 921
      * @return string $woocommerce_product_id or false if none exist
922 922
      *
923 923
      */
924
-    public static function get_course_product_id( $course_id ){
924
+    public static function get_course_product_id($course_id) {
925 925
 
926
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
926
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
927 927
 
928
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
928
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
929 929
             return false;
930 930
         }
931 931
 
@@ -941,11 +941,11 @@  discard block
 block discarded – undo
941 941
      * @param array $classes
942 942
      * @return array
943 943
      */
944
-    public static function add_woocommerce_body_class( $classes ){
944
+    public static function add_woocommerce_body_class($classes) {
945 945
 
946
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
946
+        if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) {
947 947
 
948
-            $classes[] ='woocommerce';
948
+            $classes[] = 'woocommerce';
949 949
 
950 950
         }
951 951
 
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
      *
964 964
      * @return  void
965 965
      */
966
-    public static function activate_subscription(  $order ) {
966
+    public static function activate_subscription($order) {
967 967
 
968 968
         $order_user = get_user_by('id', $order->user_id);
969 969
         $user['ID'] = $order_user->ID;
@@ -972,13 +972,13 @@  discard block
 block discarded – undo
972 972
         $user['user_url'] = $order_user->user_url;
973 973
 
974 974
         // Run through each product ordered
975
-        if ( ! sizeof($order->get_items() )>0 ) {
975
+        if ( ! sizeof($order->get_items()) > 0) {
976 976
 
977 977
             return;
978 978
 
979 979
         }
980 980
 
981
-        foreach($order->get_items() as $item) {
981
+        foreach ($order->get_items() as $item) {
982 982
 
983 983
             $product_type = '';
984 984
 
@@ -993,21 +993,21 @@  discard block
 block discarded – undo
993 993
 
994 994
             } // End If Statement
995 995
 
996
-            $_product = self::get_product_object( $item_id, $product_type );
996
+            $_product = self::get_product_object($item_id, $product_type);
997 997
 
998 998
             // Get courses that use the WC product
999 999
             $courses = array();
1000 1000
 
1001
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1001
+            if ( ! in_array($product_type, self::get_subscription_types())) {
1002 1002
 
1003
-                $courses = Sensei()->course->get_product_courses( $item_id );
1003
+                $courses = Sensei()->course->get_product_courses($item_id);
1004 1004
 
1005 1005
             } // End If Statement
1006 1006
 
1007 1007
             // Loop and add the user to the course.
1008
-            foreach ( $courses as $course_item ){
1008
+            foreach ($courses as $course_item) {
1009 1009
 
1010
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1010
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
1011 1011
 
1012 1012
             } // End For Loop
1013 1013
 
@@ -1025,13 +1025,13 @@  discard block
 block discarded – undo
1025 1025
      *
1026 1026
      * @return  void
1027 1027
      */
1028
-    public static function email_course_details(  $order ){
1028
+    public static function email_course_details($order) {
1029 1029
 
1030 1030
         global $woocommerce;
1031 1031
 
1032 1032
         // exit early if not wc-completed or wc-processing
1033
-        if( 'wc-completed' != $order->post_status
1034
-            && 'wc-processing' != $order->post_status  ) {
1033
+        if ('wc-completed' != $order->post_status
1034
+            && 'wc-processing' != $order->post_status) {
1035 1035
             return;
1036 1036
         }
1037 1037
 
@@ -1039,16 +1039,16 @@  discard block
 block discarded – undo
1039 1039
         $order_id = $order->id;
1040 1040
 
1041 1041
         //If object have items go through them all to find course
1042
-        if ( 0 < sizeof( $order_items ) ) {
1042
+        if (0 < sizeof($order_items)) {
1043 1043
 
1044
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1044
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1045 1045
             $order_contains_courses = false;
1046 1046
 
1047 1047
 
1048
-            foreach ( $order_items as $item ) {
1048
+            foreach ($order_items as $item) {
1049 1049
 
1050 1050
                 $product_type = '';
1051
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1051
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1052 1052
                     // If item has variation_id then its from variation
1053 1053
                     $item_id = $item['variation_id'];
1054 1054
                     $product_type = 'variation';
@@ -1057,9 +1057,9 @@  discard block
 block discarded – undo
1057 1057
                     $item_id = $item['product_id'];
1058 1058
                 } // End If Statement
1059 1059
 
1060
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1060
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1061 1061
 
1062
-                if( $user_id ) {
1062
+                if ($user_id) {
1063 1063
 
1064 1064
                     // Get all courses for product
1065 1065
                     $args = array(
@@ -1074,16 +1074,16 @@  discard block
 block discarded – undo
1074 1074
                         'orderby' => 'menu_order date',
1075 1075
                         'order' => 'ASC',
1076 1076
                     );
1077
-                    $courses = get_posts( $args );
1077
+                    $courses = get_posts($args);
1078 1078
 
1079
-                    if( $courses && count( $courses ) > 0 ) {
1079
+                    if ($courses && count($courses) > 0) {
1080 1080
 
1081
-                        foreach( $courses as $course ) {
1081
+                        foreach ($courses as $course) {
1082 1082
 
1083 1083
                             $title = $course->post_title;
1084
-                            $permalink = get_permalink( $course->ID );
1084
+                            $permalink = get_permalink($course->ID);
1085 1085
                             $order_contains_courses = true;
1086
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1086
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1087 1087
                         }
1088 1088
 
1089 1089
 
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
             } // end for each order item
1095 1095
 
1096 1096
             // Output Course details
1097
-            if( $order_contains_courses ){
1097
+            if ($order_contains_courses) {
1098 1098
 
1099 1099
                 echo $course_details_html;
1100 1100
 
@@ -1112,26 +1112,26 @@  discard block
 block discarded – undo
1112 1112
      * @param   int $order_id WC order ID
1113 1113
      * @return  void
1114 1114
      */
1115
-    public static function complete_order ( $order_id = 0 ) {
1115
+    public static function complete_order($order_id = 0) {
1116 1116
 
1117 1117
         $order_user = array();
1118 1118
 
1119 1119
         // Check for WooCommerce
1120
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1120
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1121 1121
             // Get order object
1122
-            $order = new WC_Order( $order_id );
1123
-            $user = get_user_by( 'id', $order->get_user_id() );
1122
+            $order = new WC_Order($order_id);
1123
+            $user = get_user_by('id', $order->get_user_id());
1124 1124
             $order_user['ID'] = $user->ID;
1125 1125
             $order_user['user_login'] = $user->user_login;
1126 1126
             $order_user['user_email'] = $user->user_email;
1127 1127
             $order_user['user_url'] = $user->user_url;
1128 1128
             // Run through each product ordered
1129
-            if ( 0 < sizeof( $order->get_items() ) ) {
1129
+            if (0 < sizeof($order->get_items())) {
1130 1130
 
1131
-                foreach( $order->get_items() as $item ) {
1131
+                foreach ($order->get_items() as $item) {
1132 1132
 
1133 1133
                     $product_type = '';
1134
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1134
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1135 1135
 
1136 1136
                         $item_id = $item['variation_id'];
1137 1137
                         $product_type = 'variation';
@@ -1142,15 +1142,15 @@  discard block
 block discarded – undo
1142 1142
 
1143 1143
                     } // End If Statement
1144 1144
 
1145
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1145
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1146 1146
 
1147 1147
                     // Get courses that use the WC product
1148
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1148
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1149 1149
 
1150 1150
                     // Loop and update those courses
1151
-                    foreach ( $courses as $course_item ) {
1151
+                    foreach ($courses as $course_item) {
1152 1152
 
1153
-                        $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user );
1153
+                        $update_course = Sensei()->woocommerce_course_update($course_item->ID, $order_user);
1154 1154
 
1155 1155
                     } // End For Loop
1156 1156
 
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
 
1159 1159
             } // End If Statement
1160 1160
             // Add meta to indicate that payment has been completed successfully
1161
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1161
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1162 1162
 
1163 1163
         } // End If Statement
1164 1164
 
@@ -1172,28 +1172,28 @@  discard block
 block discarded – undo
1172 1172
      * @param   integer| WC_Order $order_id order ID
1173 1173
      * @return  void
1174 1174
      */
1175
-    public static function cancel_order ( $order_id ) {
1175
+    public static function cancel_order($order_id) {
1176 1176
 
1177 1177
         // Get order object
1178
-        if( is_object( $order_id ) ){
1178
+        if (is_object($order_id)) {
1179 1179
 
1180 1180
             $order = $order_id;
1181 1181
 
1182
-        }else{
1182
+        } else {
1183 1183
 
1184
-            $order = new WC_Order( $order_id );
1184
+            $order = new WC_Order($order_id);
1185 1185
         }
1186 1186
 
1187 1187
         // Run through each product ordered
1188
-        if ( 0 < sizeof( $order->get_items() ) ) {
1188
+        if (0 < sizeof($order->get_items())) {
1189 1189
 
1190 1190
             // Get order user
1191
-            $user_id = $order->__get( 'user_id' );
1191
+            $user_id = $order->__get('user_id');
1192 1192
 
1193
-            foreach( $order->get_items() as $item ) {
1193
+            foreach ($order->get_items() as $item) {
1194 1194
 
1195 1195
                 $product_type = '';
1196
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1196
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1197 1197
 
1198 1198
                     $item_id = $item['variation_id'];
1199 1199
                     $product_type = 'variation';
@@ -1204,17 +1204,17 @@  discard block
 block discarded – undo
1204 1204
 
1205 1205
                 } // End If Statement
1206 1206
 
1207
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1207
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1208 1208
 
1209 1209
                 // Get courses that use the WC product
1210 1210
                 $courses = array();
1211
-                $courses = Sensei()->course->get_product_courses( $item_id );
1211
+                $courses = Sensei()->course->get_product_courses($item_id);
1212 1212
 
1213 1213
                 // Loop and update those courses
1214
-                foreach ($courses as $course_item){
1214
+                foreach ($courses as $course_item) {
1215 1215
 
1216 1216
                     // Check and Remove course from courses user meta
1217
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1217
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1218 1218
 
1219 1219
                 } // End For Loop
1220 1220
 
@@ -1235,30 +1235,30 @@  discard block
 block discarded – undo
1235 1235
      * @param   string  $product_type  '' or 'variation'
1236 1236
      * @return   WC_Product $wc_product_object
1237 1237
      */
1238
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1238
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1239 1239
 
1240 1240
         $wc_product_object = false;
1241
-        if ( 0 < intval( $wc_product_id ) ) {
1241
+        if (0 < intval($wc_product_id)) {
1242 1242
 
1243 1243
             // Get the product
1244
-            if ( function_exists( 'wc_get_product' ) ) {
1244
+            if (function_exists('wc_get_product')) {
1245 1245
 
1246
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1246
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1247 1247
 
1248
-            } elseif ( function_exists( 'get_product' ) ) {
1248
+            } elseif (function_exists('get_product')) {
1249 1249
 
1250
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1250
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1251 1251
 
1252 1252
             } else {
1253 1253
 
1254 1254
                 // Pre WC 2.0
1255
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1255
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1256 1256
 
1257
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1257
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1258 1258
 
1259 1259
                 } else {
1260 1260
 
1261
-                    $wc_product_object = new WC_Product( $wc_product_id );
1261
+                    $wc_product_object = new WC_Product($wc_product_id);
1262 1262
 
1263 1263
                 } // End If Statement
1264 1264
 
@@ -1281,19 +1281,19 @@  discard block
 block discarded – undo
1281 1281
      *
1282 1282
      * @return bool|int
1283 1283
      */
1284
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1284
+    public static function course_update($course_id = 0, $order_user = array()) {
1285 1285
 
1286 1286
         global $current_user;
1287 1287
 
1288
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1288
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1289 1289
 
1290 1290
         $data_update = false;
1291 1291
 
1292 1292
         // Get the product ID
1293
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1293
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1294 1294
 
1295 1295
         // Check if in the admin
1296
-        if ( is_admin() ) {
1296
+        if (is_admin()) {
1297 1297
 
1298 1298
             $user_login = $order_user['user_login'];
1299 1299
             $user_email = $order_user['user_email'];
@@ -1310,28 +1310,28 @@  discard block
 block discarded – undo
1310 1310
         } // End If Statement
1311 1311
 
1312 1312
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1313
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1314
-        if( 0 < absint( $course_prerequisite_id ) ) {
1313
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1314
+        if (0 < absint($course_prerequisite_id)) {
1315 1315
 
1316
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1317
-            if ( ! $prereq_course_complete ) {
1316
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1317
+            if ( ! $prereq_course_complete) {
1318 1318
 
1319 1319
                 // Remove all course user meta
1320
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1320
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1321 1321
 
1322 1322
             }
1323 1323
         }
1324 1324
 
1325
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1325
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1326 1326
 
1327
-        if( ! $is_user_taking_course ) {
1327
+        if ( ! $is_user_taking_course) {
1328 1328
 
1329
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
1329
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id) && (0 < $wc_post_id)) {
1330 1330
 
1331
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
1331
+                $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1332 1332
 
1333 1333
                 $is_user_taking_course = false;
1334
-                if ( true == $activity_logged ) {
1334
+                if (true == $activity_logged) {
1335 1335
 
1336 1336
                     $is_user_taking_course = true;
1337 1337
 
@@ -1354,14 +1354,14 @@  discard block
 block discarded – undo
1354 1354
      *
1355 1355
      * @return boolean                 Modified guest checkout setting
1356 1356
      */
1357
-    public static function disable_guest_checkout( $guest_checkout ) {
1357
+    public static function disable_guest_checkout($guest_checkout) {
1358 1358
 
1359
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1359
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1360 1360
 
1361
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1361
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1362 1362
 
1363
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1364
-                    if( isset( $product['product_id'] ) ) {
1363
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1364
+                    if (isset($product['product_id'])) {
1365 1365
 
1366 1366
                         $args = array(
1367 1367
                             'posts_per_page' => -1,
@@ -1374,11 +1374,11 @@  discard block
 block discarded – undo
1374 1374
                             )
1375 1375
                         );
1376 1376
 
1377
-                        $posts = get_posts( $args );
1377
+                        $posts = get_posts($args);
1378 1378
 
1379
-                        if( $posts && count( $posts ) > 0 ) {
1379
+                        if ($posts && count($posts) > 0) {
1380 1380
 
1381
-                            foreach( $posts as $course ) {
1381
+                            foreach ($posts as $course) {
1382 1382
                                 $guest_checkout = '';
1383 1383
                                 break;
1384 1384
 
@@ -1407,23 +1407,23 @@  discard block
 block discarded – undo
1407 1407
      *
1408 1408
      * @return string
1409 1409
      **/
1410
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1410
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1411 1411
 
1412
-        $order = new WC_Order( $order_id );
1412
+        $order = new WC_Order($order_id);
1413 1413
 
1414
-        if ( ! isset ( $order ) ) return '';
1414
+        if ( ! isset ($order)) return '';
1415 1415
 
1416
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1416
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1417 1417
 
1418 1418
             $virtual_order = true;
1419 1419
 
1420
-            if ( count( $order->get_items() ) > 0 ) {
1420
+            if (count($order->get_items()) > 0) {
1421 1421
 
1422
-                foreach( $order->get_items() as $item ) {
1422
+                foreach ($order->get_items() as $item) {
1423 1423
 
1424
-                    if ( $item['product_id'] > 0 ) {
1425
-                        $_product = $order->get_product_from_item( $item );
1426
-                        if ( ! $_product->is_virtual() ) {
1424
+                    if ($item['product_id'] > 0) {
1425
+                        $_product = $order->get_product_from_item($item);
1426
+                        if ( ! $_product->is_virtual()) {
1427 1427
 
1428 1428
                             $virtual_order = false;
1429 1429
                             break;
@@ -1437,7 +1437,7 @@  discard block
 block discarded – undo
1437 1437
             } // End If Statement
1438 1438
 
1439 1439
             // virtual order, mark as completed
1440
-            if ( $virtual_order ) {
1440
+            if ($virtual_order) {
1441 1441
 
1442 1442
                 return 'completed';
1443 1443
 
@@ -1460,14 +1460,14 @@  discard block
 block discarded – undo
1460 1460
      * @param  integer $user_id
1461 1461
      * @return boolean $user_access_permission
1462 1462
      */
1463
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1463
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1464 1464
 
1465 1465
         global $post;
1466 1466
 
1467 1467
         // ignore the current case if the following conditions are met
1468
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1469
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1470
-            || ! wcs_user_has_subscription( $user_id) ){
1468
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1469
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1470
+            || ! wcs_user_has_subscription($user_id)) {
1471 1471
 
1472 1472
             return $user_access_permission;
1473 1473
 
@@ -1477,25 +1477,25 @@  discard block
 block discarded – undo
1477 1477
         // is the subscription on the the current course?
1478 1478
 
1479 1479
         $course_id = 0;
1480
-        if ( 'course' == $post->post_type ){
1480
+        if ('course' == $post->post_type) {
1481 1481
 
1482 1482
             $course_id = $post->ID;
1483 1483
 
1484
-        } elseif ( 'lesson' == $post->post_type ) {
1484
+        } elseif ('lesson' == $post->post_type) {
1485 1485
 
1486
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1486
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1487 1487
 
1488 1488
         } else {
1489 1489
 
1490
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1491
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1490
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1491
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1492 1492
 
1493 1493
         }
1494 1494
 
1495 1495
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1496
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1497
-        $product = wc_get_product( $product_id );
1498
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1496
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1497
+        $product = wc_get_product($product_id);
1498
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1499 1499
 
1500 1500
             return $user_access_permission;
1501 1501
 
@@ -1503,19 +1503,19 @@  discard block
 block discarded – undo
1503 1503
 
1504 1504
         // give access if user has active subscription on the product otherwise restrict it.
1505 1505
         // also check if the user was added to the course directly after the subscription started.
1506
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1507
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1508
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1506
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1507
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1508
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1509 1509
 
1510 1510
             $user_access_permission = true;
1511 1511
 
1512
-        }else{
1512
+        } else {
1513 1513
 
1514 1514
             $user_access_permission = false;
1515 1515
             // do not show the WC permissions message
1516
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1517
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1518
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1516
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1517
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1518
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1519 1519
         }
1520 1520
 
1521 1521
         return $user_access_permission;
@@ -1528,9 +1528,9 @@  discard block
 block discarded – undo
1528 1528
      * @since 1.9.0
1529 1529
      * @return array
1530 1530
      */
1531
-    public static function get_subscription_types(){
1531
+    public static function get_subscription_types() {
1532 1532
 
1533
-        return array( 'subscription','subscription_variation','variable-subscription' );
1533
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1534 1534
 
1535 1535
     }
1536 1536
 
@@ -1550,15 +1550,15 @@  discard block
 block discarded – undo
1550 1550
      *
1551 1551
      * @return bool
1552 1552
      */
1553
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1553
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1554 1554
 
1555 1555
         $course_start_date = '';
1556 1556
         $subscription_start_date = '';
1557
-        $is_a_subscription ='';
1557
+        $is_a_subscription = '';
1558 1558
         $was_user_added_without_subscription = true;
1559 1559
 
1560 1560
         // if user is not on the course they were not added
1561
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1561
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1562 1562
 
1563 1563
             return false;
1564 1564
 
@@ -1567,34 +1567,34 @@  discard block
 block discarded – undo
1567 1567
         // if user doesn't have a subscription and is taking the course
1568 1568
         // they were added manually
1569 1569
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1570
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1570
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1571 1571
 
1572 1572
             return true;
1573 1573
 
1574 1574
         }
1575 1575
 
1576
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1576
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1577 1577
 
1578 1578
         // comparing dates setup data
1579
-        $course_start_date = date_create( $course_status->comment_date );
1580
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1579
+        $course_start_date = date_create($course_status->comment_date);
1580
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1581 1581
 
1582 1582
         // comparing every subscription
1583
-        foreach( $subscriptions as $subscription ){
1583
+        foreach ($subscriptions as $subscription) {
1584 1584
 
1585 1585
             // for the following statuses we know the user was not added
1586 1586
             // manually
1587 1587
             $status = $subscription->get_status();
1588
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1588
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1589 1589
 
1590 1590
                 continue;
1591 1591
 
1592 1592
             }
1593 1593
 
1594
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1594
+            $current_subscription_start_date = date_create($subscription->modified_date);
1595 1595
 
1596 1596
             // is the last updated subscription date newer than course start date
1597
-            if (  $current_subscription_start_date > $course_start_date   ) {
1597
+            if ($current_subscription_start_date > $course_start_date) {
1598 1598
 
1599 1599
                 return false;
1600 1600
 
Please login to merge, or discard this patch.