Only Payapal at checkout
<?php
/**
* Leave only Paypal, if there is a product with subscription on cart
*/
function ywsbs_only_paypal_for_subscriptions( $gateways ) {
if ( yith_added_product_as_subscription_on_cart() ) {
foreach ( $gateways as $k => $gateway ) {
if ( false === strpos( $gateway, 'WC_Gateway_Paypal' ) ) {
unset( $gateways[ $k ] );
}
}
}
return $gateways;
}
add_filter( 'woocommerce_payment_gateways', 'ywsbs_only_paypal_for_subscriptions' );
/**
* Checks if there is a product with subscription on cart
*/
function yith_added_product_as_subscription_on_cart() {
if ( ! class_exists( 'YITH_WC_Subscription' ) || empty( WC()->cart ) ) {
return false;
}
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( $_product && YITH_WC_Subscription()->is_subscription( $_product ) ) {
return true;
}
}
return false;
}