Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bernattorras/91705fdd9bceb5838808a8f11adf5ed4 to your computer and use it in GitHub Desktop.
Save bernattorras/91705fdd9bceb5838808a8f11adf5ed4 to your computer and use it in GitHub Desktop.
Disable payment gateways when the cart only contains subscriptions with free trial (allowing customers to purchase the subscription without adding any payment information)
<?php
// Disable Automatic Payments when the cart only contains subscriptions with free trial (allowing customers to purchase the subscription without adding any payment information)
add_filter('option_woocommerce_subscriptions_turn_off_automatic_payments','disable_payment_gateways_on_trial_sub', 1);
function disable_payment_gateways_on_trial_sub($automatic_payments_off){
if(!is_admin()){
$all_trial = WC_Subscriptions_Cart::all_cart_items_have_free_trial();
if($all_trial==1){
// All items in the cart contain a free trial
return 'yes'; // Turn off automatic payments (disabling payment gateways)
}
}
return $automatic_payments_off;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment