Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * FREE TRIAL EXPIRATION DATE for MONTHLY-ONGOING
- * Quarterly needs different calc !
- * for Ongoing club subscriptions (monthly and quarterly), which charge on the 1st of the next month,
- * NOT immediately (as other subscriptions do)
- *
- * @hook in classes/class-wc-subscriptions-manager.php#1855
- * @ref http://www.onlineconversion.com/unix_time.htm
- */
- add_filter ('woocommerce_subscription_calculated_trial_expiration_date','tz_wc_filter2',10,2);
- function tz_wc_filter2($expiration_date, $subscription_key) {
- // TODO: if($subscription_length == 0){ // ongoing!
- // how to find that here??
- date_default_timezone_set('America/Los_Angeles');
- $now = date('Y-m-d');
- $d = new DateTime( $now );
- $d->modify( 'last day of this month' );
- $trial_expire_date = $d->format( 'Y-m-d H:i:s' );
- $trial_expire_unix = strtotime($trial_expire_date);
- $expiration_date = $trial_expire_unix;
- return $expiration_date;
- }
- /**
- * NEXT PAYMENT DATE for MONTHLY-ONGOING
- * Quarterly needs different calc !
- * for Ongoing club subscriptions (monthly and quarterly), which charge on the 1st of the next month,
- * not immediately (as other subscriptions do)
- *
- * @hook in classes/class-wc-subscriptions-order.php#488
- */
- add_filter ('woocommerce_subscriptions_calculated_next_payment_date','tz_wc_filter3',10,3);
- function tz_wc_filter3($next_payment,$product_id,$order) {
- $product_meta = get_post_meta($order);
- $subscription_length = $product_meta['_subscription_length']['0'];
- if($subscription_length == 0){ // ongoing!
- date_default_timezone_set('America/Los_Angeles');
- $now = date('Y-m-d');
- $d = new DateTime( $now );
- $d->modify( 'first day of next month' );
- $next_payment_date = $d->format( 'Y-m-d H:i:s' );
- $next_payment_unix = strtotime($next_payment_date);
- $next_payment = $next_payment_unix;
- }
- return $next_payment;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement