/**
  * Conditionally remove any gateways that don't support pre-orders on the checkout page when the pre-order is charged
  * upon release. This is done because payment info is not required in this case so displaying gateways/payment fields
  * is not needed.
  *
  * @since 1.0
  * @param array $available_gateways
  * @return array
  */
 public function maybe_remove_unsupported_gateways($available_gateways)
 {
     // on checkout page
     if ((!is_page(woocommerce_get_page_id('pay')) || defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) {
         // remove any non-supported payment gateways
         foreach ($available_gateways as $gateway_id => $gateway) {
             if (!method_exists($gateway, 'supports') || false === $gateway->supports('pre-orders')) {
                 unset($available_gateways[$gateway_id]);
             }
         }
     }
     return $available_gateways;
 }
 /**
  * Force tokenization for pre-orders
  *
  * @since 4.1.0
  * @see SV_WC_Payment_Gateway::tokenization_forced()
  * @param boolean $force_tokenization whether tokenization should be forced
  * @return boolean true if tokenization should be forced, false otherwise
  */
 public function maybe_force_tokenization($force_tokenization)
 {
     // pay page with pre-order?
     $pay_page_pre_order = false;
     if ($this->get_gateway()->is_pay_page_gateway()) {
         $order_id = $this->get_gateway()->get_checkout_pay_page_order_id();
         if ($order_id) {
             $pay_page_pre_order = WC_Pre_Orders_Order::order_contains_pre_order($order_id) && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Order::get_pre_order_product($order_id));
         }
     }
     if (WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product()) || $pay_page_pre_order) {
         // always tokenize the card for pre-orders that are charged upon release
         $force_tokenization = true;
     }
     return $force_tokenization;
 }
 /**
  * Checks if an order will be charged upon release
  *
  * @since 1.0
  * @param object|int $order preferably the order object, or order ID if object is inconvenient to provide
  * @return bool true if the order will be charged upon , false otherwise
  */
 public static function order_will_be_charged_upon_release($order)
 {
     if (!is_object($order)) {
         $order = new WC_Order($order);
     }
     if (isset($order->order_custom_fields['_wc_pre_orders_when_charged'][0])) {
         return 'upon_release' === $order->order_custom_fields['_wc_pre_orders_when_charged'][0];
     }
     return WC_Pre_Orders_Product::product_is_charged_upon_release(self::get_pre_order_product($order));
 }
 /**
  * Helper function to return a formatted pre-order order total, e.g. '$99 charged on Dec 1, 2014'
  *
  * @since 1.0
  * @param string $total formatted order total to modify
  * @param object|int $product the product that the pre-order contains
  * @return string the new formatted order total
  */
 public static function get_formatted_pre_order_total($total, $product)
 {
     if (!is_object($product)) {
         $product = get_product($product);
     }
     // get order total format
     if (WC_Pre_Orders_Product::product_is_charged_upon_release($product)) {
         $formatted_total = get_option('wc_pre_orders_upon_release_order_total_format');
     } else {
         $formatted_total = get_option('wc_pre_orders_upfront_order_total_format');
     }
     // bail if no format is set
     if (!$formatted_total) {
         return $total;
     }
     // add localized availability date if needed
     $formatted_total = str_replace('{availability_date}', WC_Pre_Orders_Product::get_localized_availability_date($product), $formatted_total);
     // add order total
     $formatted_total = str_replace('{order_total}', $total, $formatted_total);
     return apply_filters('wc_pre_orders_pre_order_order_total', $formatted_total, $product);
 }