/**
  * Output the deposits product tab
  */
 public function output()
 {
     global $wpdb, $post;
     // To ensure views have access to the product type...
     if ($post) {
         $product_terms = wp_get_object_terms($post->ID, 'product_type');
         if ($product_terms) {
             $product_type = sanitize_title(current($product_terms)->name);
         } else {
             $product_type = apply_filters('default_product_type', 'simple');
         }
     } else {
         $product_type = false;
     }
     wp_enqueue_script('woocommerce-deposits-payment-plans');
     if (!empty($_POST)) {
         $result = $this->maybe_save_plan();
         if (is_wp_error($result)) {
             echo '<div class="error"><p>' . $result->get_error_message() . '</p></div>';
         } elseif ($result) {
             echo '<div class="updated success"><p>' . __('Plan saved successfully', 'woocommerce-deposits') . '</p></div>';
         }
     }
     if (!empty($_GET['delete_plan']) && !empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'delete_plan')) {
         $deleting_id = absint($_GET['delete_plan']);
         $wpdb->delete($wpdb->wc_deposits_payment_plans, array('ID' => $deleting_id));
         $wpdb->delete($wpdb->wc_deposits_payment_plans_schedule, array('plan_id' => $deleting_id));
         echo '<div class="updated success"><p>' . __('Plan deleted successfully', 'woocommerce-deposits') . '</p></div>';
     }
     $plan_name = '';
     $plan_description = '';
     $payment_schedule = array((object) array('amount' => 0));
     if (!empty($_REQUEST['plan_id'])) {
         $editing = absint($_REQUEST['plan_id']);
         $plan = WC_Deposits_Plans_Manager::get_plan($editing);
         $plan_name = $plan->get_name();
         $plan_description = $plan->get_description();
         $payment_schedule = $plan->get_schedule();
         $plan_type = $plan->get_type();
         include 'views/html-edit-payment-plan.php';
     } else {
         $editing = false;
         $plan_type = 'percentage';
         // default to percent for new items
         include 'views/html-payment-plans.php';
     }
 }
 /**
  * Get payment plan if used
  * @return bool or object
  */
 public static function get_payment_plan($item)
 {
     $payment_plan = !empty($item['payment_plan']) ? absint($item['payment_plan']) : 0;
     return $payment_plan ? WC_Deposits_Plans_Manager::get_plan($payment_plan) : false;
 }