Completed
Pull Request — master (#1270)
by
unknown
06:51
created
includes/class-sensei-wc.php 1 patch
Spacing   +285 added lines, -285 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,15 +11,15 @@  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
-        require_once( __DIR__ . '/hooks/woocommerce.php' );
22
+        require_once(__DIR__.'/hooks/woocommerce.php');
23 23
 
24 24
     }
25 25
     /**
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
      * @since 1.9.0
29 29
      * @return bool
30 30
      */
31
-    public static function is_woocommerce_active(){
31
+    public static function is_woocommerce_active() {
32 32
 
33
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
33
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
34 34
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
35 35
 
36 36
     } // end is_woocommerce_active
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return bool
47 47
      */
48
-    public static function is_woocommerce_present(){
48
+    public static function is_woocommerce_present() {
49 49
 
50
-        $active_plugins = (array) get_option( 'active_plugins', array() );
50
+        $active_plugins = (array) get_option('active_plugins', array());
51 51
 
52
-        if ( is_multisite() ){
52
+        if (is_multisite()) {
53 53
 
54
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
54
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
55 55
 
56 56
         }
57 57
 
58
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
58
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
59 59
 
60
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
60
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
61 61
 
62 62
     }// end is_woocommerce_present
63 63
 
@@ -70,48 +70,48 @@  discard block
 block discarded – undo
70 70
      * @param $course_id
71 71
      * @return array $user_course_orders
72 72
      */
73
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
73
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
74 74
 
75
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
75
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
76 76
 
77
-        $orders_query = new WP_Query( array(
77
+        $orders_query = new WP_Query(array(
78 78
             'post_type'   => 'shop_order',
79 79
             'posts_per_page' => -1,
80
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
80
+            'post_status' => array('wc-processing', 'wc-completed'),
81 81
             'meta_key'=> '_customer_user',
82 82
             'meta_value'=> $user_id,
83
-        ) );
83
+        ));
84 84
 
85
-        if( $orders_query->post_count == 0 ){
85
+        if ($orders_query->post_count == 0) {
86 86
 
87 87
             return false;
88 88
 
89 89
         }
90 90
 
91
-        foreach( $orders_query->get_posts() as $order ){
91
+        foreach ($orders_query->get_posts() as $order) {
92 92
 
93
-            $order = new WC_Order( $order->ID );
93
+            $order = new WC_Order($order->ID);
94 94
             $items = $order->get_items();
95 95
 
96
-            $user_orders =  array();
96
+            $user_orders = array();
97 97
 
98
-            foreach( $items as $item ){
98
+            foreach ($items as $item) {
99 99
 
100 100
                 // if the product id on the order and the one given to this function
101 101
                 // this order has been placed by the given user on the given course.
102
-                $product = wc_get_product( $item['product_id'] );
102
+                $product = wc_get_product($item['product_id']);
103 103
 
104
-                if ( $product->is_type( 'variable' )) {
104
+                if ($product->is_type('variable')) {
105 105
 
106 106
                     $item_product_id = $item['variation_id'];
107 107
 
108 108
                 } else {
109 109
 
110
-                    $item_product_id =  $item['product_id'];
110
+                    $item_product_id = $item['product_id'];
111 111
 
112 112
                 }
113 113
 
114
-                if( $course_product_id == $item_product_id ){
114
+                if ($course_product_id == $item_product_id) {
115 115
 
116 116
                     return $order->id;
117 117
 
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
      * @param $filter_links
136 136
      * @return mixed
137 137
      */
138
-    public static function add_course_archive_wc_filter_links( $filter_links ){
138
+    public static function add_course_archive_wc_filter_links($filter_links) {
139 139
 
140 140
         $free_courses = self::get_free_courses();
141 141
         $paid_courses = self::get_paid_courses();
142 142
 
143
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
143
+        if (empty($free_courses) || empty($paid_courses)) {
144 144
             // do not show any WooCommerce filters if all courses are
145 145
             // free or if all courses are paid
146 146
             return $filter_links;
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
         }
149 149
 
150 150
         $filter_links[] = array(
151
-            'id'=>'paid' ,
152
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
153
-            'title'=>__( 'Paid', 'woothemes-sensei' )
151
+            'id'=>'paid',
152
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
153
+            'title'=>__('Paid', 'woothemes-sensei')
154 154
         );
155 155
 
156 156
         $filter_links[] = array(
157 157
             'id'=>'free',
158
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
159
-            'title'=>__( 'Free', 'woothemes-sensei' )
158
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
159
+            'title'=>__('Free', 'woothemes-sensei')
160 160
         );
161 161
 
162 162
         return $filter_links;
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
      * @param WP_Query $query
174 174
      * @return WP_Query $query
175 175
      */
176
-    public static function course_archive_wc_filter_free( $query ){
176
+    public static function course_archive_wc_filter_free($query) {
177 177
 
178
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
178
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
179
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
180 180
 
181 181
             // setup the course meta query
182 182
             $meta_query = self::get_free_courses_meta_query_args();
183 183
 
184 184
             // manipulate the query to return free courses
185
-            $query->set('meta_query', $meta_query );
185
+            $query->set('meta_query', $meta_query);
186 186
 
187 187
             // don't show any paid courses
188 188
             $courses = self::get_paid_courses();
189 189
             $ids = array();
190
-            foreach( $courses as $course ){
190
+            foreach ($courses as $course) {
191 191
                 $ids[] = $course->ID;
192 192
             }
193
-            $query->set( 'post__not_in', $ids );
193
+            $query->set('post__not_in', $ids);
194 194
 
195 195
         }// end if course_filter
196 196
 
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
      * @param WP_Query $query
210 210
      * @return WP_Query $query
211 211
      */
212
-    public static function course_archive_wc_filter_paid( $query ){
212
+    public static function course_archive_wc_filter_paid($query) {
213 213
 
214
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
214
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
215
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
216 216
 
217 217
             // setup the course meta query
218 218
             $meta_query = self::get_paid_courses_meta_query_args();
219 219
 
220 220
             // manipulate the query to return free courses
221
-            $query->set('meta_query', $meta_query );
221
+            $query->set('meta_query', $meta_query);
222 222
 
223 223
         }
224 224
 
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
      * single courses if woocommerce is active allowing purchase
232 232
      * information and actions to be hooked from WooCommerce.
233 233
      */
234
-    public static function do_single_course_wc_single_product_action(){
234
+    public static function do_single_course_wc_single_product_action() {
235 235
 
236 236
         /**
237 237
          * this hooks is documented within the WooCommerce plugin.
238 238
          */
239
-        if ( Sensei_WC::is_woocommerce_active() ) {
239
+        if (Sensei_WC::is_woocommerce_active()) {
240 240
 
241
-            do_action( 'woocommerce_before_single_product' );
241
+            do_action('woocommerce_before_single_product');
242 242
 
243 243
         } // End If Statement
244 244
 
@@ -259,23 +259,23 @@  discard block
 block discarded – undo
259 259
      * @param $user_id
260 260
      * @return bool
261 261
      */
262
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
262
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
263 263
 
264 264
         // check if the course has a valid product attached to it
265 265
         // which the user should have purchased if they want to access
266 266
         // the current lesson
267
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
267
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
268
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
269 269
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
-        if( isset ($product) && is_object($product) ){
270
+        if (isset ($product) && is_object($product)) {
271 271
 
272 272
             // valid product found
273
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
273
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
274 274
 
275 275
             // product has a successful order so this user may access the content
276 276
             // this function may only return false or the default
277 277
             // returning true may override other negatives which we don't want
278
-            if( ! $order_id ){
278
+            if ( ! $order_id) {
279 279
 
280 280
                 return false;
281 281
 
@@ -298,23 +298,23 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public static function course_link_from_order( ) {
300 300
 
301
-        if( ! is_order_received_page() ){
301
+        if ( ! is_order_received_page()) {
302 302
             return;
303 303
         }
304 304
 
305
-        $order_id = get_query_var( 'order-received' );
306
-		$order = new WC_Order( $order_id );
305
+        $order_id = get_query_var('order-received');
306
+		$order = new WC_Order($order_id);
307 307
 
308 308
 		// exit early if not wc-completed or wc-processing
309
-		if( 'wc-completed' != $order->post_status
310
-            && 'wc-processing' != $order->post_status  ) {
309
+		if ('wc-completed' != $order->post_status
310
+            && 'wc-processing' != $order->post_status) {
311 311
             return;
312 312
         }
313 313
 
314 314
         $course_links = array(); // store the for links for courses purchased
315
-		foreach ( $order->get_items() as $item ) {
315
+		foreach ($order->get_items() as $item) {
316 316
 
317
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
317
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
318 318
 
319 319
                 // If item has variation_id then its a variation of the product
320 320
                 $item_id = $item['variation_id'];
@@ -326,28 +326,28 @@  discard block
 block discarded – undo
326 326
 
327 327
             } // End If Statement
328 328
 
329
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
329
+            $user_id = get_post_meta($order->id, '_customer_user', true);
330 330
 
331
-            if( $user_id ) {
331
+            if ($user_id) {
332 332
 
333 333
                 // Get all courses for product
334 334
                 $args = Sensei_Course::get_default_query_args();
335
-                $args['meta_query'] = array( array(
335
+                $args['meta_query'] = array(array(
336 336
                             'key' => '_course_woocommerce_product',
337 337
                             'value' => $item_id
338
-                        ) );
338
+                        ));
339 339
                 $args['orderby'] = 'menu_order date';
340 340
                 $args['order'] = 'ASC';
341 341
 
342 342
                 // loop through courses
343
-                $courses = get_posts( $args );
344
-                if( $courses && count( $courses ) > 0 ) {
343
+                $courses = get_posts($args);
344
+                if ($courses && count($courses) > 0) {
345 345
 
346
-                    foreach( $courses as $course ) {
346
+                    foreach ($courses as $course) {
347 347
 
348 348
                         $title = $course->post_title;
349
-                        $permalink = get_permalink( $course->ID );
350
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
349
+                        $permalink = get_permalink($course->ID);
350
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
351 351
 
352 352
                     } // end for each
353 353
 
@@ -358,24 +358,24 @@  discard block
 block discarded – undo
358 358
         }// end loop through orders
359 359
 
360 360
         // add the courses to the WooCommerce notice
361
-        if( ! empty( $course_links) ){
361
+        if ( ! empty($course_links)) {
362 362
 
363 363
             $courses_html = _nx(
364 364
                 'You have purchased the following course:',
365 365
                 'You have purchased the following courses:',
366
-                count( $course_links ),
366
+                count($course_links),
367 367
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368 368
             );
369 369
 
370
-            foreach( $course_links as $link ){
370
+            foreach ($course_links as $link) {
371 371
 
372
-                $courses_html .= '<li>' . $link . '</li>';
372
+                $courses_html .= '<li>'.$link.'</li>';
373 373
 
374 374
             }
375 375
 
376 376
             $courses_html .= ' </ul>';
377 377
 
378
-            wc_add_notice( $courses_html, 'success' );
378
+            wc_add_notice($courses_html, 'success');
379 379
         }
380 380
 
381 381
 	} // end course_link_order_form
@@ -388,20 +388,20 @@  discard block
 block discarded – undo
388 388
      *
389 389
      * @since 1.9.0
390 390
      */
391
-    public static function course_in_cart_message(){
391
+    public static function course_in_cart_message() {
392 392
 
393 393
         global $post;
394 394
 
395
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
395
+        if (self::is_course_in_cart($post->ID)) { ?>
396 396
 
397 397
             <div class="sensei-message info">
398 398
                 <?php
399 399
 
400
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
400
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
401
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
402
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
403 403
 
404
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
404
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
405 405
 
406 406
                 ?>
407 407
             </div>
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
      * @param $course_id
416 416
      * @return bool
417 417
      */
418
-    public static function is_course_in_cart( $course_id ){
418
+    public static function is_course_in_cart($course_id) {
419 419
 
420
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
420
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
421
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
422 422
 
423
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
423
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
424 424
 
425
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
425
+            if (self::is_product_in_cart($wc_post_id)) {
426 426
 
427 427
                 return true;
428 428
 
@@ -440,20 +440,20 @@  discard block
 block discarded – undo
440 440
      * @param $product_id
441 441
      * @return bool
442 442
      */
443
-    public static function is_product_in_cart( $product_id ){
443
+    public static function is_product_in_cart($product_id) {
444 444
 
445
-        if ( 0 < $product_id ) {
445
+        if (0 < $product_id) {
446 446
 
447
-            $product = wc_get_product( $product_id );
447
+            $product = wc_get_product($product_id);
448 448
 
449 449
             $parent_id = '';
450
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
450
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
451 451
                 $wc_product_id = $product->parent->id;
452 452
             }
453
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
453
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
454 454
 
455 455
                 $cart_product = $values['data'];
456
-                if( $product_id == $cart_product->id ) {
456
+                if ($product_id == $cart_product->id) {
457 457
 
458 458
                     return true;
459 459
 
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
      *  @type int $wp_post_id
476 476
      * }
477 477
      */
478
-    public static function get_free_product_ids(){
478
+    public static function get_free_product_ids() {
479 479
 
480
-        return  get_posts( array(
480
+        return  get_posts(array(
481 481
             'post_type' => 'product',
482 482
             'posts_per_page' => '1000',
483 483
             'fields' => 'ids',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @since 1.9.0
503 503
      * @return array $wp_meta_query_param
504 504
      */
505
-    public static function get_free_courses_meta_query_args(){
505
+    public static function get_free_courses_meta_query_args() {
506 506
 
507 507
         return array(
508 508
             'relation' => 'OR',
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
      * @since 1.9.0
527 527
      * @return array $wp_query_meta_query_args_param
528 528
      */
529
-    public static function get_paid_courses_meta_query_args(){
529
+    public static function get_paid_courses_meta_query_args() {
530 530
 
531 531
         $paid_product_ids = self::get_paid_product_ids();
532 532
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                 'key'     => '_course_woocommerce_product',
536 536
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
537 537
                 // query
538
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
538
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
539 539
                 'compare' => 'IN',
540 540
             ),
541 541
         );
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
      * @since 1.9.0
550 550
      * @return array $product_query_args
551 551
      */
552
-    public static function get_paid_products_on_sale_query_args(){
552
+    public static function get_paid_products_on_sale_query_args() {
553 553
 
554 554
         $args = array(
555 555
                    'post_type' 		=> 'product',
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
                    'suppress_filters' 	=> 0
560 560
         );
561 561
 
562
-        $args[ 'fields' ]     = 'ids';
562
+        $args['fields']     = 'ids';
563 563
 
564
-        $args[ 'meta_query' ] = array(
564
+        $args['meta_query'] = array(
565 565
             'relation' => 'AND',
566 566
             array(
567 567
                 'key'=> '_regular_price',
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
      *
589 589
      * @return array
590 590
      */
591
-    public static function get_paid_products_not_on_sale_query_args(){
591
+    public static function get_paid_products_not_on_sale_query_args() {
592 592
 
593 593
         $args = array(
594 594
             'post_type' 		=> 'product',
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
             'suppress_filters' 	=> 0
599 599
         );
600 600
 
601
-        $args[ 'fields' ]     = 'ids';
602
-        $args[ 'meta_query' ] = array(
601
+        $args['fields']     = 'ids';
602
+        $args['meta_query'] = array(
603 603
             'relation' => 'AND',
604 604
             array(
605 605
                 'key'=> '_regular_price',
@@ -625,24 +625,24 @@  discard block
 block discarded – undo
625 625
      *
626 626
      * @return array $woocommerce_paid_product_ids
627 627
      */
628
-    public static function get_paid_product_ids(){
628
+    public static function get_paid_product_ids() {
629 629
 
630 630
         // get all the paid WooCommerce products that has regular
631 631
         // and sale price greater than 0
632 632
         // will be used later to check for course with the id as meta
633
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
633
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
634 634
 
635 635
         // get all the paid WooCommerce products that has regular price
636 636
         // greater than 0 without a sale price
637 637
         // will be used later to check for course with the id as meta
638
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
638
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
639 639
 
640 640
         // combine products ID's with regular and sale price grater than zero and those without
641 641
         // sale but regular price greater than zero
642
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
642
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
643 643
 
644 644
         // if
645
-        if( empty($woocommerce_paid_product_ids) ){
645
+        if (empty($woocommerce_paid_product_ids)) {
646 646
             return array( );
647 647
         }
648 648
         return $woocommerce_paid_product_ids;
@@ -661,20 +661,20 @@  discard block
 block discarded – undo
661 661
      *
662 662
      * @return array
663 663
      */
664
-    public static function get_free_courses(){
664
+    public static function get_free_courses() {
665 665
 
666 666
         $free_course_query_args = Sensei_Course::get_default_query_args();
667
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
667
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
668 668
 
669 669
         // don't show any paid courses
670 670
         $courses = self::get_paid_courses();
671 671
         $ids = array();
672
-        foreach( $courses as $course ){
672
+        foreach ($courses as $course) {
673 673
             $ids[] = $course->ID;
674 674
         }
675
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
675
+        $free_course_query_args['post__not_in'] = $ids;
676 676
 
677
-        return get_posts( $free_course_query_args );
677
+        return get_posts($free_course_query_args);
678 678
 
679 679
     }
680 680
 
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
      * @since 1.9.0
685 685
      * @return array
686 686
      */
687
-    public static function get_paid_courses(){
687
+    public static function get_paid_courses() {
688 688
 
689 689
         $paid_course_query_args = Sensei_Course::get_default_query_args();
690 690
 
691
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
691
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
692 692
 
693
-        return get_posts(  $paid_course_query_args );
693
+        return get_posts($paid_course_query_args);
694 694
     }
695 695
 
696 696
     /**
@@ -705,17 +705,17 @@  discard block
 block discarded – undo
705 705
      * @param int $course_id
706 706
      * @return string $html markup for the button or nothing if user not allowed to buy
707 707
      */
708
-    public static function the_add_to_cart_button_html( $course_id ){
708
+    public static function the_add_to_cart_button_html($course_id) {
709 709
 
710
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
710
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
711 711
             return '';
712 712
         }
713 713
 
714
-        $wc_post_id = self::get_course_product_id( $course_id );
714
+        $wc_post_id = self::get_course_product_id($course_id);
715 715
 
716 716
         // Check if customer purchased the product
717
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
-            || empty( $wc_post_id ) ) {
717
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
718
+            || empty($wc_post_id)) {
719 719
 
720 720
             return '';
721 721
 
@@ -723,15 +723,15 @@  discard block
 block discarded – undo
723 723
 
724 724
         // based on simple.php in WC templates/single-product/add-to-cart/
725 725
         // Get the product
726
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
726
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
727 727
 
728 728
         // do not show the button for invalid products, non purchasable products, out
729 729
         // of stock product or if course is already in cart
730
-        if ( ! isset ( $product )
731
-            || ! is_object( $product )
730
+        if ( ! isset ($product)
731
+            || ! is_object($product)
732 732
             || ! $product->is_purchasable()
733 733
             || ! $product->is_in_stock()
734
-            || self::is_course_in_cart( $wc_post_id ) ) {
734
+            || self::is_course_in_cart($wc_post_id)) {
735 735
 
736 736
             return '';
737 737
 
@@ -742,23 +742,23 @@  discard block
 block discarded – undo
742 742
         //
743 743
         ?>
744 744
 
745
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
745
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
746 746
               class="cart"
747 747
               method="post"
748 748
               enctype="multipart/form-data">
749 749
 
750
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
750
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
751 751
 
752 752
             <input type="hidden" name="quantity" value="1" />
753 753
 
754
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
754
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
755 755
 
756 756
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
757
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
757
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
758 758
 
759
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
759
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
760 760
 
761
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
761
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
762 762
 
763 763
                     <?php } ?>
764 764
 
@@ -767,8 +767,8 @@  discard block
 block discarded – undo
767 767
             <?php } ?>
768 768
 
769 769
             <button type="submit" class="single_add_to_cart_button button alt">
770
-                <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?>
771
-                <?php echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text ); ?>
770
+                <?php $button_text = $product->get_price_html().' - '.__('Purchase this Course', 'woothemes-sensei'); ?>
771
+                <?php echo apply_filters('sensei_wc_single_add_to_cart_button_text', $button_text); ?>
772 772
             </button>
773 773
 
774 774
         </form>
@@ -787,26 +787,26 @@  discard block
 block discarded – undo
787 787
      *
788 788
      * @return string $message
789 789
      */
790
-    public static function alter_no_permissions_message( $message, $post_id ){
790
+    public static function alter_no_permissions_message($message, $post_id) {
791 791
 
792
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
792
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
793 793
             return  $message;
794 794
         }
795 795
 
796
-        $product_id = self::get_course_product_id( $post_id );
796
+        $product_id = self::get_course_product_id($post_id);
797 797
 
798
-        if( ! $product_id
799
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
798
+        if ( ! $product_id
799
+            || self::has_customer_bought_product(get_current_user_id(), $product_id)) {
800 800
 
801 801
             return $message;
802 802
 
803 803
         }
804 804
 
805 805
         ob_start();
806
-        self::the_course_no_permissions_message( $post_id );
806
+        self::the_course_no_permissions_message($post_id);
807 807
         $woocommerce_course_no_permissions_message = ob_get_clean();
808 808
 
809
-        return $woocommerce_course_no_permissions_message ;
809
+        return $woocommerce_course_no_permissions_message;
810 810
 
811 811
     }
812 812
     /**
@@ -815,16 +815,16 @@  discard block
 block discarded – undo
815 815
      *
816 816
      * @since 1.9.0
817 817
      */
818
-    public static function the_course_no_permissions_message( $course_id ){
818
+    public static function the_course_no_permissions_message($course_id) {
819 819
 
820 820
         // login link
821
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
822
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
821
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
822
+        $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
823 823
 
824 824
         ?>
825 825
 
826 826
         <span class="add-to-cart-login">
827
-            <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
827
+            <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?>
828 828
         </span>
829 829
 
830 830
     <?php }
@@ -839,45 +839,45 @@  discard block
 block discarded – undo
839 839
      *
840 840
      * @return bool
841 841
      */
842
-    public static function has_customer_bought_product ( $user_id, $product_id ){
842
+    public static function has_customer_bought_product($user_id, $product_id) {
843 843
 
844
-        $orders = get_posts( array(
844
+        $orders = get_posts(array(
845 845
             'numberposts' => -1,
846 846
             'post_type' => 'shope_order',
847 847
             'meta_key'    => '_customer_user',
848
-            'meta_value'  => intval( $user_id ),
849
-            'post_status' => array( 'wc-complete','wc-processing' ),
850
-        ) );
848
+            'meta_value'  => intval($user_id),
849
+            'post_status' => array('wc-complete', 'wc-processing'),
850
+        ));
851 851
 
852
-        foreach ( $orders as $order_id ) {
852
+        foreach ($orders as $order_id) {
853 853
 
854
-            $order = new WC_Order( $order_id->ID );
854
+            $order = new WC_Order($order_id->ID);
855 855
 
856 856
             // wc-active is the subscriptions complete status
857
-            if ( ! in_array( $order->post_status, array( 'wc-complete','wc-processing' ) ) ){
857
+            if ( ! in_array($order->post_status, array('wc-complete', 'wc-processing'))) {
858 858
 
859 859
                 continue;
860 860
 
861 861
             }
862 862
 
863
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
863
+            if ( ! (0 < sizeof($order->get_items()))) {
864 864
 
865 865
                 continue;
866 866
 
867 867
             }
868 868
 
869
-            foreach( $order->get_items() as $item ) {
869
+            foreach ($order->get_items() as $item) {
870 870
 
871 871
                 // Check if user has bought product
872
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
872
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
873 873
 
874 874
                     // Check if user has an active subscription for product
875
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
876
-                        $sub_key = wcs_get_subscription( $order );
877
-                        if( $sub_key ) {
878
-                            $sub = wcs_get_subscription( $sub_key );
879
-                            if( $sub && isset( $sub['status'] ) ) {
880
-                                if( 'active' == $sub['status'] ) {
875
+                    if (class_exists('WC_Subscriptions_Manager')) {
876
+                        $sub_key = wcs_get_subscription($order);
877
+                        if ($sub_key) {
878
+                            $sub = wcs_get_subscription($sub_key);
879
+                            if ($sub && isset($sub['status'])) {
880
+                                if ('active' == $sub['status']) {
881 881
                                     return true;
882 882
                                 } else {
883 883
                                     return false;
@@ -906,11 +906,11 @@  discard block
 block discarded – undo
906 906
      * @return string $woocommerce_product_id or false if none exist
907 907
      *
908 908
      */
909
-    public static function get_course_product_id( $course_id ){
909
+    public static function get_course_product_id($course_id) {
910 910
 
911
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
911
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
912 912
 
913
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
913
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
914 914
             return false;
915 915
         }
916 916
 
@@ -924,11 +924,11 @@  discard block
 block discarded – undo
924 924
      * @param array $classes
925 925
      * @return array
926 926
      */
927
-    public static function add_woocommerce_body_class( $classes ){
927
+    public static function add_woocommerce_body_class($classes) {
928 928
 
929
-        if( ! in_array( 'woocommerce', $classes ) ){
929
+        if ( ! in_array('woocommerce', $classes)) {
930 930
 
931
-            $classes[] ='woocommerce';
931
+            $classes[] = 'woocommerce';
932 932
 
933 933
         }
934 934
 
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
      *
947 947
      * @return  void
948 948
      */
949
-    public static function activate_subscription(  $order ) {
949
+    public static function activate_subscription($order) {
950 950
 
951 951
         $order_user = get_user_by('id', $order->user_id);
952 952
         $user['ID'] = $order_user->ID;
@@ -955,13 +955,13 @@  discard block
 block discarded – undo
955 955
         $user['user_url'] = $order_user->user_url;
956 956
 
957 957
         // Run through each product ordered
958
-        if ( ! sizeof($order->get_items() )>0 ) {
958
+        if ( ! sizeof($order->get_items()) > 0) {
959 959
 
960 960
             return;
961 961
 
962 962
         }
963 963
 
964
-        foreach($order->get_items() as $item) {
964
+        foreach ($order->get_items() as $item) {
965 965
 
966 966
             $product_type = '';
967 967
 
@@ -976,21 +976,21 @@  discard block
 block discarded – undo
976 976
 
977 977
             } // End If Statement
978 978
 
979
-            $_product = self::get_product_object( $item_id, $product_type );
979
+            $_product = self::get_product_object($item_id, $product_type);
980 980
 
981 981
             // Get courses that use the WC product
982 982
             $courses = array();
983 983
 
984
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
984
+            if ( ! in_array($product_type, self::get_subscription_types())) {
985 985
 
986
-                $courses = Sensei()->course->get_product_courses( $item_id );
986
+                $courses = Sensei()->course->get_product_courses($item_id);
987 987
 
988 988
             } // End If Statement
989 989
 
990 990
             // Loop and add the user to the course.
991
-            foreach ( $courses as $course_item ){
991
+            foreach ($courses as $course_item) {
992 992
 
993
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
993
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
994 994
 
995 995
             } // End For Loop
996 996
 
@@ -1008,13 +1008,13 @@  discard block
 block discarded – undo
1008 1008
      *
1009 1009
      * @return  void
1010 1010
      */
1011
-    public static function email_course_details(  $order ){
1011
+    public static function email_course_details($order) {
1012 1012
 
1013 1013
         global $woocommerce;
1014 1014
 
1015 1015
         // exit early if not wc-completed or wc-processing
1016
-        if( 'wc-completed' != $order->post_status
1017
-            && 'wc-processing' != $order->post_status  ) {
1016
+        if ('wc-completed' != $order->post_status
1017
+            && 'wc-processing' != $order->post_status) {
1018 1018
             return;
1019 1019
         }
1020 1020
 
@@ -1022,16 +1022,16 @@  discard block
 block discarded – undo
1022 1022
         $order_id = $order->id;
1023 1023
 
1024 1024
         //If object have items go through them all to find course
1025
-        if ( 0 < sizeof( $order_items ) ) {
1025
+        if (0 < sizeof($order_items)) {
1026 1026
 
1027
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1027
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1028 1028
             $order_contains_courses = false;
1029 1029
 
1030 1030
 
1031
-            foreach ( $order_items as $item ) {
1031
+            foreach ($order_items as $item) {
1032 1032
 
1033 1033
                 $product_type = '';
1034
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1034
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1035 1035
                     // If item has variation_id then its from variation
1036 1036
                     $item_id = $item['variation_id'];
1037 1037
                     $product_type = 'variation';
@@ -1040,9 +1040,9 @@  discard block
 block discarded – undo
1040 1040
                     $item_id = $item['product_id'];
1041 1041
                 } // End If Statement
1042 1042
 
1043
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1043
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1044 1044
 
1045
-                if( $user_id ) {
1045
+                if ($user_id) {
1046 1046
 
1047 1047
                     // Get all courses for product
1048 1048
                     $args = array(
@@ -1057,16 +1057,16 @@  discard block
 block discarded – undo
1057 1057
                         'orderby' => 'menu_order date',
1058 1058
                         'order' => 'ASC',
1059 1059
                     );
1060
-                    $courses = get_posts( $args );
1060
+                    $courses = get_posts($args);
1061 1061
 
1062
-                    if( $courses && count( $courses ) > 0 ) {
1062
+                    if ($courses && count($courses) > 0) {
1063 1063
 
1064
-                        foreach( $courses as $course ) {
1064
+                        foreach ($courses as $course) {
1065 1065
 
1066 1066
                             $title = $course->post_title;
1067
-                            $permalink = get_permalink( $course->ID );
1067
+                            $permalink = get_permalink($course->ID);
1068 1068
                             $order_contains_courses = true;
1069
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1069
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1070 1070
                         }
1071 1071
 
1072 1072
 
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
             } // end for each order item
1078 1078
 
1079 1079
             // Output Course details
1080
-            if( $order_contains_courses ){
1080
+            if ($order_contains_courses) {
1081 1081
 
1082 1082
                 echo $course_details_html;
1083 1083
 
@@ -1095,26 +1095,26 @@  discard block
 block discarded – undo
1095 1095
      * @param   int $order_id WC order ID
1096 1096
      * @return  void
1097 1097
      */
1098
-    public static function complete_order ( $order_id = 0 ) {
1098
+    public static function complete_order($order_id = 0) {
1099 1099
 
1100 1100
         $order_user = array();
1101 1101
 
1102 1102
         // Check for WooCommerce
1103
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1103
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1104 1104
             // Get order object
1105
-            $order = new WC_Order( $order_id );
1106
-            $user = get_user_by( 'id', $order->get_user_id() );
1105
+            $order = new WC_Order($order_id);
1106
+            $user = get_user_by('id', $order->get_user_id());
1107 1107
             $order_user['ID'] = $user->ID;
1108 1108
             $order_user['user_login'] = $user->user_login;
1109 1109
             $order_user['user_email'] = $user->user_email;
1110 1110
             $order_user['user_url'] = $user->user_url;
1111 1111
             // Run through each product ordered
1112
-            if ( 0 < sizeof( $order->get_items() ) ) {
1112
+            if (0 < sizeof($order->get_items())) {
1113 1113
 
1114
-                foreach( $order->get_items() as $item ) {
1114
+                foreach ($order->get_items() as $item) {
1115 1115
 
1116 1116
                     $product_type = '';
1117
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1117
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1118 1118
 
1119 1119
                         $item_id = $item['variation_id'];
1120 1120
                         $product_type = 'variation';
@@ -1125,15 +1125,15 @@  discard block
 block discarded – undo
1125 1125
 
1126 1126
                     } // End If Statement
1127 1127
 
1128
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1128
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1129 1129
 
1130 1130
                     // Get courses that use the WC product
1131
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1131
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1132 1132
 
1133 1133
                     // Loop and update those courses
1134
-                    foreach ( $courses as $course_item ) {
1134
+                    foreach ($courses as $course_item) {
1135 1135
 
1136
-                        $update_course = Sensei()->woocommerce_course_update( $course_item->ID, $order_user );
1136
+                        $update_course = Sensei()->woocommerce_course_update($course_item->ID, $order_user);
1137 1137
 
1138 1138
                     } // End For Loop
1139 1139
 
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 
1142 1142
             } // End If Statement
1143 1143
             // Add meta to indicate that payment has been completed successfully
1144
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1144
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1145 1145
 
1146 1146
         } // End If Statement
1147 1147
 
@@ -1155,28 +1155,28 @@  discard block
 block discarded – undo
1155 1155
      * @param   integer| WC_Order $order_id order ID
1156 1156
      * @return  void
1157 1157
      */
1158
-    public static function cancel_order ( $order_id ) {
1158
+    public static function cancel_order($order_id) {
1159 1159
 
1160 1160
         // Get order object
1161
-        if( is_object( $order_id ) ){
1161
+        if (is_object($order_id)) {
1162 1162
 
1163 1163
             $order = $order_id;
1164 1164
 
1165
-        }else{
1165
+        } else {
1166 1166
 
1167
-            $order = new WC_Order( $order_id );
1167
+            $order = new WC_Order($order_id);
1168 1168
         }
1169 1169
 
1170 1170
         // Run through each product ordered
1171
-        if ( 0 < sizeof( $order->get_items() ) ) {
1171
+        if (0 < sizeof($order->get_items())) {
1172 1172
 
1173 1173
             // Get order user
1174
-            $user_id = $order->__get( 'user_id' );
1174
+            $user_id = $order->__get('user_id');
1175 1175
 
1176
-            foreach( $order->get_items() as $item ) {
1176
+            foreach ($order->get_items() as $item) {
1177 1177
 
1178 1178
                 $product_type = '';
1179
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1179
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1180 1180
 
1181 1181
                     $item_id = $item['variation_id'];
1182 1182
                     $product_type = 'variation';
@@ -1187,17 +1187,17 @@  discard block
 block discarded – undo
1187 1187
 
1188 1188
                 } // End If Statement
1189 1189
 
1190
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1190
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1191 1191
 
1192 1192
                 // Get courses that use the WC product
1193 1193
                 $courses = array();
1194
-                $courses = Sensei()->course->get_product_courses( $item_id );
1194
+                $courses = Sensei()->course->get_product_courses($item_id);
1195 1195
 
1196 1196
                 // Loop and update those courses
1197
-                foreach ($courses as $course_item){
1197
+                foreach ($courses as $course_item) {
1198 1198
 
1199 1199
                     // Check and Remove course from courses user meta
1200
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1200
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1201 1201
 
1202 1202
                 } // End For Loop
1203 1203
 
@@ -1218,30 +1218,30 @@  discard block
 block discarded – undo
1218 1218
      * @param   string  $product_type  '' or 'variation'
1219 1219
      * @return   WC_Product $wc_product_object
1220 1220
      */
1221
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1221
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1222 1222
 
1223 1223
         $wc_product_object = false;
1224
-        if ( 0 < intval( $wc_product_id ) ) {
1224
+        if (0 < intval($wc_product_id)) {
1225 1225
 
1226 1226
             // Get the product
1227
-            if ( function_exists( 'wc_get_product' ) ) {
1227
+            if (function_exists('wc_get_product')) {
1228 1228
 
1229
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1229
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1230 1230
 
1231
-            } elseif ( function_exists( 'get_product' ) ) {
1231
+            } elseif (function_exists('get_product')) {
1232 1232
 
1233
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1233
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1234 1234
 
1235 1235
             } else {
1236 1236
 
1237 1237
                 // Pre WC 2.0
1238
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1238
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1239 1239
 
1240
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1240
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1241 1241
 
1242 1242
                 } else {
1243 1243
 
1244
-                    $wc_product_object = new WC_Product( $wc_product_id );
1244
+                    $wc_product_object = new WC_Product($wc_product_id);
1245 1245
 
1246 1246
                 } // End If Statement
1247 1247
 
@@ -1264,19 +1264,19 @@  discard block
 block discarded – undo
1264 1264
      *
1265 1265
      * @return bool|int
1266 1266
      */
1267
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1267
+    public static function course_update($course_id = 0, $order_user = array()) {
1268 1268
 
1269 1269
         global $current_user;
1270 1270
 
1271
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1271
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1272 1272
 
1273 1273
         $data_update = false;
1274 1274
 
1275 1275
         // Get the product ID
1276
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1276
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1277 1277
 
1278 1278
         // Check if in the admin
1279
-        if ( is_admin() ) {
1279
+        if (is_admin()) {
1280 1280
 
1281 1281
             $user_login = $order_user['user_login'];
1282 1282
             $user_email = $order_user['user_email'];
@@ -1293,28 +1293,28 @@  discard block
 block discarded – undo
1293 1293
         } // End If Statement
1294 1294
 
1295 1295
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1296
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1297
-        if( 0 < absint( $course_prerequisite_id ) ) {
1296
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1297
+        if (0 < absint($course_prerequisite_id)) {
1298 1298
 
1299
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1300
-            if ( ! $prereq_course_complete ) {
1299
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1300
+            if ( ! $prereq_course_complete) {
1301 1301
 
1302 1302
                 // Remove all course user meta
1303
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1303
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1304 1304
 
1305 1305
             }
1306 1306
         }
1307 1307
 
1308
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1308
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1309 1309
 
1310
-        if( ! $is_user_taking_course ) {
1310
+        if ( ! $is_user_taking_course) {
1311 1311
 
1312
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
1312
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id) && (0 < $wc_post_id)) {
1313 1313
 
1314
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
1314
+                $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1315 1315
 
1316 1316
                 $is_user_taking_course = false;
1317
-                if ( true == $activity_logged ) {
1317
+                if (true == $activity_logged) {
1318 1318
 
1319 1319
                     $is_user_taking_course = true;
1320 1320
 
@@ -1337,14 +1337,14 @@  discard block
 block discarded – undo
1337 1337
      *
1338 1338
      * @return boolean                 Modified guest checkout setting
1339 1339
      */
1340
-    public static function disable_guest_checkout( $guest_checkout ) {
1340
+    public static function disable_guest_checkout($guest_checkout) {
1341 1341
 
1342
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1342
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1343 1343
 
1344
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1344
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1345 1345
 
1346
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1347
-                    if( isset( $product['product_id'] ) ) {
1346
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1347
+                    if (isset($product['product_id'])) {
1348 1348
 
1349 1349
                         $args = array(
1350 1350
                             'posts_per_page' => -1,
@@ -1357,11 +1357,11 @@  discard block
 block discarded – undo
1357 1357
                             )
1358 1358
                         );
1359 1359
 
1360
-                        $posts = get_posts( $args );
1360
+                        $posts = get_posts($args);
1361 1361
 
1362
-                        if( $posts && count( $posts ) > 0 ) {
1362
+                        if ($posts && count($posts) > 0) {
1363 1363
 
1364
-                            foreach( $posts as $course ) {
1364
+                            foreach ($posts as $course) {
1365 1365
                                 $guest_checkout = '';
1366 1366
                                 break;
1367 1367
 
@@ -1390,23 +1390,23 @@  discard block
 block discarded – undo
1390 1390
      *
1391 1391
      * @return string
1392 1392
      **/
1393
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1393
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1394 1394
 
1395
-        $order = new WC_Order( $order_id );
1395
+        $order = new WC_Order($order_id);
1396 1396
 
1397
-        if ( ! isset ( $order ) ) return '';
1397
+        if ( ! isset ($order)) return '';
1398 1398
 
1399
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1399
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1400 1400
 
1401 1401
             $virtual_order = true;
1402 1402
 
1403
-            if ( count( $order->get_items() ) > 0 ) {
1403
+            if (count($order->get_items()) > 0) {
1404 1404
 
1405
-                foreach( $order->get_items() as $item ) {
1405
+                foreach ($order->get_items() as $item) {
1406 1406
 
1407
-                    if ( $item['product_id'] > 0 ) {
1408
-                        $_product = $order->get_product_from_item( $item );
1409
-                        if ( ! $_product->is_virtual() ) {
1407
+                    if ($item['product_id'] > 0) {
1408
+                        $_product = $order->get_product_from_item($item);
1409
+                        if ( ! $_product->is_virtual()) {
1410 1410
 
1411 1411
                             $virtual_order = false;
1412 1412
                             break;
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
             } // End If Statement
1421 1421
 
1422 1422
             // virtual order, mark as completed
1423
-            if ( $virtual_order ) {
1423
+            if ($virtual_order) {
1424 1424
 
1425 1425
                 return 'completed';
1426 1426
 
@@ -1443,14 +1443,14 @@  discard block
 block discarded – undo
1443 1443
      * @param  integer $user_id
1444 1444
      * @return boolean $user_access_permission
1445 1445
      */
1446
-    public static function get_subscription_permission( $user_access_permission, $user_id ){
1446
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1447 1447
 
1448 1448
         global $post;
1449 1449
 
1450 1450
         // ignore the current case if the following conditions are met
1451
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1452
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1453
-            || ! wcs_user_has_subscription( $user_id) ){
1451
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1452
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1453
+            || ! wcs_user_has_subscription($user_id)) {
1454 1454
 
1455 1455
             return $user_access_permission;
1456 1456
 
@@ -1460,25 +1460,25 @@  discard block
 block discarded – undo
1460 1460
         // is the subscription on the the current course?
1461 1461
 
1462 1462
         $course_id = 0;
1463
-        if ( 'course' == $post->post_type ){
1463
+        if ('course' == $post->post_type) {
1464 1464
 
1465 1465
             $course_id = $post->ID;
1466 1466
 
1467
-        } elseif ( 'lesson' == $post->post_type ) {
1467
+        } elseif ('lesson' == $post->post_type) {
1468 1468
 
1469
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1469
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1470 1470
 
1471 1471
         } else {
1472 1472
 
1473
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1474
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1473
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1474
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1475 1475
 
1476 1476
         }
1477 1477
 
1478 1478
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1479
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1480
-        $product = wc_get_product( $product_id );
1481
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1479
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1480
+        $product = wc_get_product($product_id);
1481
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1482 1482
 
1483 1483
             return $user_access_permission;
1484 1484
 
@@ -1486,19 +1486,19 @@  discard block
 block discarded – undo
1486 1486
 
1487 1487
         // give access if user has active subscription on the product otherwise restrict it.
1488 1488
         // also check if the user was added to the course directly after the subscription started.
1489
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1490
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1491
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1489
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1490
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1491
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1492 1492
 
1493 1493
             $user_access_permission = true;
1494 1494
 
1495
-        }else{
1495
+        } else {
1496 1496
 
1497 1497
             $user_access_permission = false;
1498 1498
             // do not show the WC permissions message
1499
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1500
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1501
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1499
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1500
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1501
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1502 1502
         }
1503 1503
 
1504 1504
         return $user_access_permission;
@@ -1511,9 +1511,9 @@  discard block
 block discarded – undo
1511 1511
      * @since 1.9.0
1512 1512
      * @return array
1513 1513
      */
1514
-    public static function get_subscription_types(){
1514
+    public static function get_subscription_types() {
1515 1515
 
1516
-        return array( 'subscription','subscription_variation','variable-subscription' );
1516
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1517 1517
 
1518 1518
     }
1519 1519
 
@@ -1533,15 +1533,15 @@  discard block
 block discarded – undo
1533 1533
      *
1534 1534
      * @return bool
1535 1535
      */
1536
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1536
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1537 1537
 
1538 1538
         $course_start_date = '';
1539 1539
         $subscription_start_date = '';
1540
-        $is_a_subscription ='';
1540
+        $is_a_subscription = '';
1541 1541
         $was_user_added_without_subscription = true;
1542 1542
 
1543 1543
         // if user is not on the course they were not added
1544
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1544
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1545 1545
 
1546 1546
             return false;
1547 1547
 
@@ -1550,34 +1550,34 @@  discard block
 block discarded – undo
1550 1550
         // if user doesn't have a subscription and is taking the course
1551 1551
         // they were added manually
1552 1552
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1553
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1553
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1554 1554
 
1555 1555
             return true;
1556 1556
 
1557 1557
         }
1558 1558
 
1559
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1559
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1560 1560
 
1561 1561
         // comparing dates setup data
1562
-        $course_start_date = date_create( $course_status->comment_date );
1563
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1562
+        $course_start_date = date_create($course_status->comment_date);
1563
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1564 1564
 
1565 1565
         // comparing every subscription
1566
-        foreach( $subscriptions as $subscription ){
1566
+        foreach ($subscriptions as $subscription) {
1567 1567
 
1568 1568
             // for the following statuses we know the user was not added
1569 1569
             // manually
1570 1570
             $status = $subscription->get_status();
1571
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1571
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1572 1572
 
1573 1573
                 continue;
1574 1574
 
1575 1575
             }
1576 1576
 
1577
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1577
+            $current_subscription_start_date = date_create($subscription->modified_date);
1578 1578
 
1579 1579
             // is the last updated subscription date newer than course start date
1580
-            if (  $current_subscription_start_date > $course_start_date   ) {
1580
+            if ($current_subscription_start_date > $course_start_date) {
1581 1581
 
1582 1582
                 return false;
1583 1583
 
Please login to merge, or discard this patch.