Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active December 3, 2021 14:49
Show Gist options
  • Save jrick1229/99fff8a6b61580e5b0d6b000399573fe to your computer and use it in GitHub Desktop.
Save jrick1229/99fff8a6b61580e5b0d6b000399573fe to your computer and use it in GitHub Desktop.
Keep subscription active when order is paid for via SEPA. Works with parent and renewal orders.
<?php
/*
*
* Keep subscription active when order is paid for via SEPA.
* Works with parent and renewal orders.
*
*/
add_action( 'woocommerce_order_status_changed', 'wcs_sub_active_SEPA', 10, 4 );
function wcs_sub_active_SEPA( $order_id, $status_from, $status_to, $order ) {
if($order->get_payment_method() === 'stripe_sepa' && $status_to === 'on-hold') {
if ( wcs_order_contains_subscription( $order, 'any' ) ) {
$subscriptions = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'any' ) ) );
foreach( $subscriptions as $subscription_id => $subscription ){
$subscription->update_status( 'active' );
}
}
}
}
/*
* uncomment to calculate 'Next payment date' based on last renewal order creation date,
* NOT the date payment was actually received
*/
//add_filter( 'wcs_calculate_next_payment_from_last_payment', '__return_false' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment