mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 23:02:56 +00:00
2.2.3
This commit is contained in:

committed by
Remco Tolsma

parent
a7af434d12
commit
0691aa36da
@@ -16,6 +16,73 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for wc_doing_it_wrong.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $function
|
||||
* @param string $version
|
||||
* @param string $replacement
|
||||
*/
|
||||
function wcs_doing_it_wrong( $function, $message, $version ) {
|
||||
|
||||
if ( function_exists( 'wc_doing_it_wrong' ) ) {
|
||||
wc_doing_it_wrong( $function, $message, $version );
|
||||
} else {
|
||||
// Reimplment wc_doing_it_wrong() when WC 3.0 is not active
|
||||
if ( is_ajax() ) {
|
||||
do_action( 'doing_it_wrong_run', $function, $message, $version );
|
||||
error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
|
||||
} else {
|
||||
_doing_it_wrong( esc_attr( $function ), esc_attr( $message ), esc_attr( $version ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for wcs_deprecated_function to improve handling of ajax requests, even when
|
||||
* WooCommerce 3.0's wcs_deprecated_function method is not available.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $function
|
||||
* @param string $version
|
||||
* @param string $replacement
|
||||
*/
|
||||
function wcs_deprecated_function( $function, $version, $replacement = null ) {
|
||||
|
||||
if ( function_exists( 'wc_deprecated_function' ) ) {
|
||||
wc_deprecated_function( $function, $version, $replacement );
|
||||
} else {
|
||||
// Reimplment wcs_deprecated_function() when WC 3.0 is not active
|
||||
if ( is_ajax() ) {
|
||||
do_action( 'deprecated_function_run', $function, $replacement, $version );
|
||||
$log_string = "The {$function} function is deprecated since version {$version}.";
|
||||
$log_string .= $replacement ? " Replace with {$replacement}." : '';
|
||||
error_log( $log_string );
|
||||
} else {
|
||||
_deprecated_function( esc_attr( $function ), esc_attr( $version ), esc_attr( $replacement ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reimplement similar logic to wc_deprecated_argument() without the first parameter confusion.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $argument
|
||||
* @param string $version
|
||||
* @param string $message
|
||||
*/
|
||||
function wcs_deprecated_argument( $function, $version, $message = null ) {
|
||||
if ( is_ajax() ) {
|
||||
do_action( 'deprecated_argument_run', $function, $message, $version );
|
||||
error_log( "{$function} was called with an argument that is deprecated since version {$version}. {$message}" );
|
||||
} else {
|
||||
_deprecated_argument( esc_attr( $function ), esc_attr( $version ), esc_attr( $message ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string key for a subscription used in Subscriptions prior to 2.0.
|
||||
*
|
||||
@@ -37,7 +104,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
function wcs_get_old_subscription_key( WC_Subscription $subscription ) {
|
||||
|
||||
// Get an ID to use as the order ID
|
||||
$order_id = isset( $subscription->order->id ) ? $subscription->order->id : $subscription->id;
|
||||
$order_id = ( false == $subscription->get_parent_id() ) ? $subscription->get_id() : $subscription->get_parent_id();
|
||||
|
||||
// Get an ID to use as the product ID
|
||||
$subscription_items = $subscription->get_items();
|
||||
@@ -128,8 +195,15 @@ function wcs_get_subscription_in_deprecated_structure( WC_Subscription $subscrip
|
||||
$completed_payments = array();
|
||||
|
||||
if ( $subscription->get_completed_payment_count() ) {
|
||||
if ( ! empty( $subscription->order ) && $subscription->order->has_status( $subscription->get_paid_order_statuses() ) ) {
|
||||
$completed_payments[] = $subscription->order->post->post_date_gmt;
|
||||
|
||||
$order = $subscription->get_parent();
|
||||
|
||||
if ( ! empty( $order ) ) {
|
||||
$parent_order_created_date = wcs_get_objects_property( $order, 'date_created' );
|
||||
|
||||
if ( ! is_null( $parent_order_created_date ) ) {
|
||||
$completed_payments[] = wcs_get_datetime_utc_string( $parent_order_created_date );
|
||||
}
|
||||
}
|
||||
|
||||
$paid_renewal_order_ids = get_posts( array(
|
||||
@@ -143,14 +217,17 @@ function wcs_get_subscription_in_deprecated_structure( WC_Subscription $subscrip
|
||||
array(
|
||||
'key' => '_subscription_renewal',
|
||||
'compare' => '=',
|
||||
'value' => $subscription->id,
|
||||
'value' => $subscription->get_id(),
|
||||
'type' => 'numeric',
|
||||
),
|
||||
),
|
||||
) );
|
||||
|
||||
foreach ( $paid_renewal_order_ids as $paid_renewal_order_id ) {
|
||||
$completed_payments[] = get_post_field( 'post_date_gmt', $paid_renewal_order_id );
|
||||
$date_created = wcs_get_objects_property( wc_get_order( $paid_renewal_order_id ), 'date_created' );
|
||||
if ( ! is_null( $date_created ) ) {
|
||||
$completed_payments[] = wcs_get_datetime_utc_string( $date_created );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,27 +237,27 @@ function wcs_get_subscription_in_deprecated_structure( WC_Subscription $subscrip
|
||||
if ( ! empty( $item ) ) {
|
||||
|
||||
$deprecated_subscription_object = array(
|
||||
'order_id' => $subscription->order->id,
|
||||
'order_id' => $subscription->get_parent_id(),
|
||||
'product_id' => isset( $item['product_id'] ) ? $item['product_id'] : 0,
|
||||
'variation_id' => isset( $item['variation_id'] ) ? $item['variation_id'] : 0,
|
||||
'status' => $subscription->get_status(),
|
||||
|
||||
// Subscription billing details
|
||||
'period' => $subscription->billing_period,
|
||||
'interval' => $subscription->billing_interval,
|
||||
'length' => wcs_estimate_periods_between( ( 0 == $subscription->get_time( 'trial_end' ) ) ? $subscription->get_time( 'start' ) : $subscription->get_time( 'trial_end' ), $subscription->get_time( 'end' ) + 120, $subscription->billing_period, 'floor' ) / $subscription->billing_interval, // Since subscriptions no longer have a length, we need to calculate the length given the start and end dates and the period.
|
||||
'period' => $subscription->get_billing_period(),
|
||||
'interval' => $subscription->get_billing_interval(),
|
||||
'length' => wcs_estimate_periods_between( ( 0 == $subscription->get_time( 'trial_end' ) ) ? $subscription->get_time( 'date_created' ) : $subscription->get_time( 'trial_end' ), $subscription->get_time( 'end' ) + 120, $subscription->get_billing_period(), 'floor' ) / $subscription->get_billing_interval(), // Since subscriptions no longer have a length, we need to calculate the length given the start and end dates and the period.
|
||||
|
||||
// Subscription dates
|
||||
'start_date' => $subscription->get_date( 'start' ),
|
||||
'start_date' => $subscription->get_date( 'date_created' ),
|
||||
'expiry_date' => $subscription->get_date( 'end' ),
|
||||
'end_date' => $subscription->has_status( wcs_get_subscription_ended_statuses() ) ? $subscription->get_date( 'end' ) : 0,
|
||||
'trial_expiry_date' => $subscription->get_date( 'trial_end' ),
|
||||
|
||||
// Payment & status change history
|
||||
'failed_payments' => $subscription->failed_payment_count,
|
||||
'failed_payments' => $subscription->get_failed_payment_count(),
|
||||
'completed_payments' => $completed_payments,
|
||||
'suspension_count' => $subscription->suspension_count,
|
||||
'last_payment_date' => $subscription->get_date( 'last_payment' ),
|
||||
'suspension_count' => $subscription->get_suspension_count(),
|
||||
'last_payment_date' => $subscription->get_date( 'last_order_date_created' ),
|
||||
);
|
||||
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user