コード例 #1
0
 /**
  * Always require payment if the order have a booking that requires confirmation.
  *
  * @param  bool $needs_payment
  * @param  WC_Cart $cart
  *
  * @return bool
  */
 public function booking_requires_confirmation($needs_payment, $cart)
 {
     if (!$needs_payment) {
         foreach ($cart->cart_contents as $cart_item) {
             if (wc_booking_requires_confirmation($cart_item['product_id'])) {
                 $needs_payment = true;
                 break;
             }
         }
     }
     return $needs_payment;
 }
コード例 #2
0
 /**
  * Removes all products when cart have a booking which requires confirmation
  *
  * @param  bool $passed
  * @param  int  $product_id
  *
  * @return bool
  */
 public function validate_booking_requires_confirmation($passed, $product_id)
 {
     if (wc_booking_requires_confirmation($product_id)) {
         $items = WC()->cart->get_cart();
         foreach ($items as $item_key => $item) {
             if (!isset($item['booking']) || !wc_booking_requires_confirmation($item['product_id'])) {
                 WC()->cart->remove_cart_item($item_key);
             }
         }
     } elseif (wc_booking_cart_requires_confirmation()) {
         // Remove bookings that requires confirmation.
         $this->remove_booking_that_requires_confirmation();
         wc_add_notice(__('A booking that requires confirmation has been removed from your cart. It is not possible to complete the purchased along with a booking that doesn\'t require confirmation.', 'woocommerce-bookings'), 'notice');
     }
     return $passed;
 }
コード例 #3
0
/**
 * Check if the order has booking that requires confirmation.
 *
 * @param  WC_Order $order
 *
 * @return bool
 */
function wc_booking_order_requires_confirmation($order)
{
    $requires = false;
    if ($order) {
        foreach ($order->get_items() as $item) {
            if (wc_booking_requires_confirmation($item['product_id'])) {
                $requires = true;
                break;
            }
        }
    }
    return $requires;
}
コード例 #4
0
 /**
  * Removes all products when cart have a booking which requires confirmation
  *
  * @param  bool $passed
  * @param  int  $product_id
  *
  * @return bool
  */
 public function validate_booking_requires_confirmation($passed, $product_id)
 {
     if (wc_booking_requires_confirmation($product_id)) {
         // Remove any other cart items.
         WC()->cart->empty_cart();
     } elseif (wc_booking_cart_requires_confirmation()) {
         // Remove bookings that requires confirmation.
         $this->remove_booking_that_requires_confirmation();
         wc_add_notice(__('A booking that requires confirmation has been removed from your cart. It is not possible to complete the purchased along with a booking that doesn\'t require confirmation.', 'woocommerce-bookings'), 'notice');
     }
     return $passed;
 }