Skip to content

Commit

Permalink
Improve is_available() check for minimum/maximum amounts, better chec…
Browse files Browse the repository at this point in the history
…k renewal payment amounts
  • Loading branch information
davdebcom committed May 3, 2018
1 parent 6b7620c commit 9c0bdd3
Showing 1 changed file with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,26 +268,48 @@ public function is_available() {
// Only in WooCommerce checkout, check min/max amounts
if ( WC()->cart ) {

// Get the regular order total for this order
// Check the current (normal) order total
$order_total = $this->get_order_total();

// If WooCommerce Subscriptions is installed, get the recurring order total
if ( class_exists( 'WC_Subscriptions_Product' ) ) {
$order_total = $this->get_recurring_total();
}
// Don't check SEPA Direct Debit, as it's only available for recurring payments
if ( $this->id !== 'mollie_wc_gateway_directdebit' ) {

// If order total is more then zero, check min/max amounts
if ( $order_total > 0 ) {
// Validate min amount
if ( 0 < $this->min_amount && $this->min_amount > $order_total ) {
return false;
}

// If order total is more then zero, check min/max amounts
if ( $order_total > 0 ) {
// Validate min amount
if ( 0 < $this->min_amount && $this->min_amount > $order_total ) {
return false;
// Validate max amount
if ( 0 < $this->max_amount && $this->max_amount < $order_total ) {
return false;
}
}
}

// If WooCommerce Subscriptions is installed, also check recurring order total
if ( class_exists( 'WC_Subscriptions' ) ) {

foreach ( $this->get_recurring_total() as $order_total ) {

// If order total is more then zero, check min/max amounts
if ( $order_total > 0 ) {
// Validate min amount
if ( 0 < $this->min_amount && $this->min_amount > $order_total ) {
return false;
}

// Validate max amount
if ( 0 < $this->max_amount && $this->max_amount < $order_total ) {
return false;
}
}

// Validate max amount
if ( 0 < $this->max_amount && $this->max_amount < $order_total ) {
return false;
}

}

}

return true;
Expand Down Expand Up @@ -1642,11 +1664,15 @@ protected function get_recurring_total() {

if ( isset( WC()->cart ) ) {

foreach ( WC()->cart->cart_contents as $item_key => $item ) {
$item_quantity = $item['quantity'];
$item_price = WC_Subscriptions_Product::get_price( $item['product_id'] );
$item_recurring_total = $item_quantity * $item_price;
$this->recurring_total += $item_recurring_total;
$this->recurring_total = array (); // Reset for cached carts

foreach ( WC()->cart->recurring_carts as $cart ) {

if ( ! $cart->prices_include_tax ) {
$this->recurring_total[] = $cart->cart_contents_total;
} else {
$this->recurring_total[] = $cart->cart_contents_total + $cart->tax_total;
}
}
}

Expand Down

0 comments on commit 9c0bdd3

Please sign in to comment.