Skip to content

Commit

Permalink
Only show Direct Debit (mandate via ...) gateways if cart or order …
Browse files Browse the repository at this point in the history
…contains a subscription product.
  • Loading branch information
rvdsteege committed Jul 24, 2017
1 parent e4bcb00 commit a2b8405
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/DirectDebitBancontactGateway.php
Expand Up @@ -69,7 +69,9 @@ public function get_available_payment_gateways( $available_gateways ) {
return $available_gateways;
}

if ( WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && wcs_order_contains_subscription( $_GET['order_id'] ) ) ) {
$order_id = filter_input( INPUT_GET, 'order_id', FILTER_SANITIZE_STRING );

if ( WC_Subscriptions_Cart::cart_contains_subscription() || wcs_order_contains_subscription( $order_id ) ) {
return $available_gateways;
}

Expand Down
26 changes: 26 additions & 0 deletions src/DirectDebitIDealGateway.php
Expand Up @@ -44,6 +44,9 @@ public function __construct() {
// Handle subscription payments
add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'process_subscription_payment' ), 10, 2 );

// Filters
add_filter( 'woocommerce_available_payment_gateways', array( $this, 'get_available_payment_gateways' ) );

parent::__construct();
}

Expand Down Expand Up @@ -83,4 +86,27 @@ function init_form_fields() {
$this->form_fields['description']['default'] = __( 'By using this payment method you authorize us via iDEAL to debit payments from your bank account.', 'pronamic_ideal' );
$this->form_fields['icon']['default'] = plugins_url( 'images/sepa-ideal/wc-sepa-ideal.png', Pronamic_WP_Pay_Plugin::$file );
}

/**
* Only show gateway if cart or order contains a subscription product.
*
* @since unreleased
*/
public function get_available_payment_gateways( $available_gateways ) {
if ( ! class_exists( 'WC_Subscriptions_Cart' ) || ! function_exists( 'wcs_order_contains_subscription' ) ) {
return $available_gateways;
}

$order_id = filter_input( INPUT_GET, 'order_id', FILTER_SANITIZE_STRING );

if ( WC_Subscriptions_Cart::cart_contains_subscription() || wcs_order_contains_subscription( $order_id ) ) {
return $available_gateways;
}

if ( isset( $available_gateways[ self::ID ] ) ) {
unset( $available_gateways[ self::ID ] );
}

return $available_gateways;
}
}

0 comments on commit a2b8405

Please sign in to comment.