-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate last_payment for imported subscriptions #146
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ public static function init() { | |
*/ | ||
public static function setup_importer() { | ||
|
||
if ( class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.0', '>=' ) ) { | ||
add_filter('woocommerce_subscription_get_' . 'last_payment' . '_date', array(WCS_Importer_Exporter::class, 'last_payment_calculation'), 10, 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filter name here would be changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true, but the number of times i've come across a theme which extended part of woocommerce but was not able to find the do_action/filter it was adding onto is many as the dynamic breakdown stops easy searching and then i need to work out where to place the wild card's. I've corrected this to your suggested wording as they should know how to find this if they have come this far. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doh, this was used elsewhere in the class so it's a silly mistake, am too use to using non static classes for adding to filters with class |
||
} | ||
if ( is_admin() ) { | ||
if ( class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.0', '>=' ) ) { | ||
self::$wcs_exporter = new WCS_Export_Admin(); | ||
|
@@ -60,11 +63,32 @@ public static function setup_importer() { | |
} | ||
} | ||
|
||
/** | ||
* This is to calculate last_payment when the last payment not set by import | ||
* this is done by taking next interval and removing twice. | ||
* Only change from 0 if it was an imported subscription | ||
* | ||
* @param $date | ||
* @param $subscription @class WC_Subscription | ||
* @param $timezone | ||
* @return $date or date of last payment calulation | ||
*/ | ||
public static function last_payment_calculation($date, $subscription, $timezone ) { | ||
if ($date == 0 && "importer" === $subscription->__get("created_via")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another silly mistake as i did the right thing on the next check.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too use to java with having fully named getters and setters and an ide that can work it out for me. phpstorm let me down on this one :$. if anyone stumbles upon this (including future me) and wondering about magic __get usage, it is http://php.net/manual/en/language.oop5.overloading.php#object.get |
||
$next_payment = strtotime($subscription->get_date('next_payment')); | ||
$next_interval = wcs_add_time( $subscription->billing_interval, $subscription->billing_period, $next_payment ); | ||
$last_payment_cal = $next_payment - ($next_interval - $next_payment); | ||
return gmdate( 'Y-m-d H:i:s',$last_payment_cal); | ||
} | ||
return $date; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected, the downgrade/upgrade looks at gmt time it seems, but its good to handle both, also updated documentation to match from other locations in subscriptions/woocommerce. |
||
} | ||
|
||
/** | ||
* Include Docs & Settings links on the Plugins administration screen | ||
* | ||
* @since 1.0 | ||
* @param mixed $links | ||
* @return array | ||
*/ | ||
public static function action_links( $links ) { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is unnecessary. The filter will only be called with Subscriptions 2.0, and when Subscriptions is active, so it's safe to just add the filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know, have removed.