Beispiel #1
0
 /**
  * Responds to when an order is cancelled.
  *
  * @since   1.2.0
  * @since   1.9.0 Move function to the Sensei_WC class
  * @param   integer| WC_Order $order_id order ID
  * @return  void
  */
 public static function cancel_order($order_id)
 {
     // Get order object
     if (is_object($order_id)) {
         $order = $order_id;
     } else {
         $order = new WC_Order($order_id);
     }
     // Run through each product ordered
     if (0 < sizeof($order->get_items())) {
         // Get order user
         $user_id = $order->__get('user_id');
         foreach ($order->get_items() as $item) {
             $product_type = '';
             if (isset($item['variation_id']) && 0 < $item['variation_id']) {
                 $item_id = $item['variation_id'];
                 $product_type = 'variation';
             } else {
                 $item_id = $item['product_id'];
             }
             // End If Statement
             $_product = Sensei_WC::get_product_object($item_id, $product_type);
             // Get courses that use the WC product
             $courses = array();
             $courses = Sensei()->course->get_product_courses($item_id);
             // Loop and update those courses
             foreach ($courses as $course_item) {
                 // Check and Remove course from courses user meta
                 $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
             }
             // End For Loop
         }
         // End For Loop
     }
     // End If Statement
 }
Beispiel #2
0
 /**
  * Returns the WooCommerce Product Object
  *
  * The code caters for pre and post WooCommerce 2.2 installations.
  *
  * @deprecated since 1.9.0
  * @since   1.1.1
  *
  * @param   integer $wc_product_id Product ID or Variation ID
  * @param   string  $product_type  '' or 'variation'
  *
  * @return   WC_Product $wc_product_object
  */
 public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '')
 {
     return Sensei_WC::get_product_object($wc_product_id, $product_type);
 }