I need help with dates in Woo Subscriptions checkout for an animal charity website using woocommerce.
I just want to change the First Payment Date (or maybe trial period end date ?) in the cart on the checkout, for each subscription order. The value of the date actually comes from a gravity form linked on various "products".
• The problem is that I don't know how to modify the subscription dates on the checkout.
• The main idea is that each customer could choose his own subscription first payment date for the product, because in the SEPA/IBAN context field has to be customized with the value of the payment date chosen (using "Sepa Direct Debit" plugin to export the XML SEPA file for each day). A customer should be able to subscribe to a product one day but the payment date could be delayed by the customer himself. I'm not sure but I think the good way would be to customize the Trial Period length, in order to the payment to be hold until the date comes.
• Usually I find the filters or functions I need, but I hardly understand the Woo Subscription documentation, as it provides no example and use syntax like this https://docs.woocommerce.com/document/subscriptions/develop/functions/
• I tried to see how worked "first-payment-date-for-woocommerce-subscriptions" plugin but its action takes place in backoffice and the same dates are applied to the product, not the cart.
• I think something can be done with things like :
_subscription_trial_length
add_filter( 'woocommerce_subscriptions_product_trial_length')
update_post_meta( $subid , '_schedule_next_payment', $var)
add_action( 'woocommerce_before_calculate_totals')
$cart_item['data']->set_length( $mydate )
I tried to adapt this function but it doesn't work :
add_action( 'woocommerce_before_calculate_totals', 'before_calculate_totals_action_callback', 10, 1 );
function before_calculate_totals_action_callback( $cart ) {
if ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
$maxlength = []; // Initializing
// TEST
$paymentdate = '2020-07-07 11:11:11';
// First loop (get)
foreach ( $cart->get_cart() as $cart_item ){
if ( in_array( $cart_item['data']->get_type(), array('subscription', 'subscription_variation') ) ) {
$maxlength[] = (float) $cart_item['data']->get_length();
}
}
// Get the highest value
$maxlength = max($maxlength);
// Second loop (set)
foreach ( $cart->get_cart() as $cart_item ){
if ( is_a( $cart_item['data'], 'WC_Product_Subscription' ) || is_a( $cart_item['data'], 'WC_Product_Subscription_Variation' ) ) {
// $cart_item['data']->set_length( $maxlength );
$cart_item['data']->set_length( $paymentdate );
}
}
}
I've tried lots of things, the question is, is there a simple filter of function somewhere that works ? Please h-e-l-p !
Woocommerce by default allows you to enable renewal synchronization to align subscription renewal day. This feature is available only for the shop admin and the end customer has no option to change on his own. Still merchants or shop admin can change the subscription date manually for the end customer upon his request.
The feature is more likely to be introduced by Woocommerce in the future. You can check this page https://docs.woocommerce.com/document/subscriptions/renewal-synchronisation/ for more details on subscription renewals.