Last active
August 29, 2015 14:23
-
-
Save WillBrubaker/7966dc6977bf68f652a8 to your computer and use it in GitHub Desktop.
Dynamically adjust WooCommerce Subscriptions first synced payment date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I have a WooCommerce Subscription product set up to bill every 2nd month | |
* The product is also set up to synchronize payments to the 25th of each month | |
* and the products are shipped on the 1st of every 2nd month - the shipping | |
* schedule is fixed, i.e. shipments only go out on even numbered months | |
* | |
* How can I prevent my customers from being billed 5 weeks before their first box | |
* actually goes out? | |
*/ | |
add_filter( 'woocommerce_subscriptions_synced_first_payment_date', 'wooninja_filter_first_payment_date', 10, 2 ); | |
function wooninja_filter_first_payment_date( $first_payment_date, $product ) { | |
$day = (int) date( 'j', $first_payment_date ); | |
$month = (int) date( 'n', $first_payment_date ); | |
//Edit the product id (666) below as necessary | |
//the day condition is to prevent trying to increment | |
//a month if that might result in an invalid date string | |
if ( 666 == $product->id && 0 == $month % 2 && $day <= 28 ) { | |
$first_payment_date = strtotime( $month + 1 . '/' . date( 'j/Y H:i:s', $first_payment_date ) ); | |
} | |
return $first_payment_date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment