Skip to content

Commit

Permalink
Updates to 6.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
WooCommerce committed Jul 16, 2024
1 parent 73217b1 commit b2a4dd8
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 113 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
*** WooCommerce Subscriptions Changelog ***

2024-07-16 - version 6.5.0
* Add: Include trial_period, suspension_count, and requires_manual_renewal in the REST API response for subscriptions.
* Update: When a renewal order's payment is skipped, include the order's current status in the note to help troubleshooting.
* Fix: Label improvements on subscription and order page templates.
* Fix: Fixed an issue with subscriptions containing multiple renewal orders to mark a random item as processing, instead of the last order.
* Fix: Prevent errors from invalid subscription objects during customer payment method updates.
* Dev: Updated subscriptions-core to 7.3.0.

2024-06-28 - version 6.4.1
* Fix: Resolved errors preventing subscription-related webhooks from sending on WC 9.0 stores.

Expand Down
23 changes: 21 additions & 2 deletions includes/api/class-wc-rest-subscriptions-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ public function prepare_object_for_response( $object, $request ) {
}

// Add subscription specific data to the base order response data.
$response->data['billing_period'] = $object->get_billing_period();
$response->data['billing_interval'] = $object->get_billing_interval();
$response->data['billing_period'] = $object->get_billing_period();
$response->data['billing_interval'] = $object->get_billing_interval();
$response->data['trial_period'] = $object->get_trial_period();
$response->data['suspension_count'] = $object->get_suspension_count();
$response->data['requires_manual_renewal'] = $object->get_requires_manual_renewal();

foreach ( wcs_get_subscription_date_types() as $date_type => $date_name ) {
$date = $object->get_date( wcs_normalise_date_type_key( $date_type ) );
Expand Down Expand Up @@ -396,6 +399,22 @@ public function get_item_schema() {
'enum' => array_keys( wcs_get_subscription_period_strings() ),
'context' => array( 'view', 'edit' ),
),
'trial_period' => array(
'description' => __( 'Trial period for the subscription.', 'woocommerce-subscriptions' ),
'type' => 'string',
'enum' => array_keys( wcs_get_subscription_period_strings() ),
'context' => array( 'view', 'edit' ),
),
'suspension_count' => array(
'description' => __( 'The number of times the subscription has been suspended since the last payment.', 'woocommerce-subscriptions' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
),
'requires_manual_renewal' => array(
'description' => __( 'Whether the subscription requires manual renewal.', 'woocommerce-subscriptions' ),
'type' => 'boolean',
'context' => array( 'view', 'edit' ),
),
'payment_details' => array(
'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
'type' => 'object',
Expand Down
8 changes: 5 additions & 3 deletions includes/gateways/class-wc-subscriptions-payment-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static function gateway_scheduled_subscription_payment( $subscription_id,
$latest_renewal_order = $subscription->get_last_order( 'all', 'renewal' );

if ( empty( $latest_renewal_order ) ) {
$subscription->add_order_note( __( "Renewal order payment processing was skipped because we couldn't locate the latest renewal order.", 'woocommerce_subscriptions' ) );
return;
}

Expand All @@ -94,9 +95,10 @@ public static function gateway_scheduled_subscription_payment( $subscription_id,
} elseif ( $latest_renewal_order->get_total() > 0 ) {
$subscription->add_order_note(
sprintf(
/* Translators: placeholder is a subscription renewal order ID as a link */
__( 'Payment processing of the renewal order %s was skipped because it is already paid.', 'woocommerce_subscriptions' ),
'<a href="' . esc_url( $latest_renewal_order->get_edit_order_url() ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $latest_renewal_order->get_order_number() . '</a>'
/* Translators: 1: placeholder is a subscription renewal order ID as a link, 2: placeholder the order's current status */
__( 'Payment processing of the renewal order %1$s was skipped because it is already paid (%2$s).', 'woocommerce_subscriptions' ),
'<a href="' . esc_url( $latest_renewal_order->get_edit_order_url() ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $latest_renewal_order->get_order_number() . '</a>',
wc_get_order_status_name( $latest_renewal_order->get_status() )
)
);
}
Expand Down
162 changes: 95 additions & 67 deletions languages/woocommerce-subscriptions.pot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitb6faa2b65c1d08bc372be5e5be1acee6::getLoader();
return ComposerAutoloaderInit8810e821b269df6dcc857459761afe4a::getLoader();
8 changes: 4 additions & 4 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitb6faa2b65c1d08bc372be5e5be1acee6
class ComposerAutoloaderInit8810e821b269df6dcc857459761afe4a
{
private static $loader;

Expand All @@ -24,12 +24,12 @@ public static function getLoader()

require __DIR__ . '/platform_check.php';

spl_autoload_register(array('ComposerAutoloaderInitb6faa2b65c1d08bc372be5e5be1acee6', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8810e821b269df6dcc857459761afe4a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitb6faa2b65c1d08bc372be5e5be1acee6', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8810e821b269df6dcc857459761afe4a', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8810e821b269df6dcc857459761afe4a::getInitializer($loader));

$loader->register(true);

Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6
class ComposerStaticInit8810e821b269df6dcc857459761afe4a
{
public static $prefixLengthsPsr4 = array (
'C' =>
Expand Down Expand Up @@ -129,9 +129,9 @@ class ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb6faa2b65c1d08bc372be5e5be1acee6::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8810e821b269df6dcc857459761afe4a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8810e821b269df6dcc857459761afe4a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8810e821b269df6dcc857459761afe4a::$classMap;

}, null, ClassLoader::class);
}
Expand Down
14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@
},
{
"name": "woocommerce/subscriptions-core",
"version": "7.2.0",
"version_normalized": "7.2.0.0",
"version": "7.3.0",
"version_normalized": "7.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/Automattic/woocommerce-subscriptions-core.git",
"reference": "9f42efee04a8e8966c2fda22c25ee1793fe9839e"
"reference": "f144df5b7ee103c4e792d8ddc0e72f1839def8b2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Automattic/woocommerce-subscriptions-core/zipball/9f42efee04a8e8966c2fda22c25ee1793fe9839e",
"reference": "9f42efee04a8e8966c2fda22c25ee1793fe9839e",
"url": "https://api.github.com/repos/Automattic/woocommerce-subscriptions-core/zipball/f144df5b7ee103c4e792d8ddc0e72f1839def8b2",
"reference": "f144df5b7ee103c4e792d8ddc0e72f1839def8b2",
"shasum": ""
},
"require": {
Expand All @@ -179,7 +179,7 @@
"woocommerce/woocommerce-sniffs": "0.1.0",
"yoast/phpunit-polyfills": "1.1.0"
},
"time": "2024-06-13T01:14:44+00:00",
"time": "2024-07-16T05:33:10+00:00",
"type": "wordpress-plugin",
"extra": {
"phpcodesniffer-search-depth": 2
Expand Down Expand Up @@ -209,7 +209,7 @@
"description": "Sell products and services with recurring payments in your WooCommerce Store.",
"homepage": "https://github.com/Automattic/woocommerce-subscriptions-core",
"support": {
"source": "https://github.com/Automattic/woocommerce-subscriptions-core/tree/7.2.0",
"source": "https://github.com/Automattic/woocommerce-subscriptions-core/tree/7.3.0",
"issues": "https://github.com/Automattic/woocommerce-subscriptions-core/issues"
},
"install-path": "../woocommerce/subscriptions-core"
Expand Down
18 changes: 9 additions & 9 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'woocommerce/woocommerce-subscriptions',
'pretty_version' => 'dev-release/6.4.1',
'version' => 'dev-release/6.4.1',
'reference' => '1731999c38ad73e9593177e016f02aa815ed4dca',
'pretty_version' => 'dev-release/6.5.0',
'version' => 'dev-release/6.5.0',
'reference' => '75ec0cbc31ee105f66684b10fb0433b44b3e58e9',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -32,18 +32,18 @@
),
),
'woocommerce/subscriptions-core' => array(
'pretty_version' => '7.2.0',
'version' => '7.2.0.0',
'reference' => '9f42efee04a8e8966c2fda22c25ee1793fe9839e',
'pretty_version' => '7.3.0',
'version' => '7.3.0.0',
'reference' => 'f144df5b7ee103c4e792d8ddc0e72f1839def8b2',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../woocommerce/subscriptions-core',
'aliases' => array(),
'dev_requirement' => false,
),
'woocommerce/woocommerce-subscriptions' => array(
'pretty_version' => 'dev-release/6.4.1',
'version' => 'dev-release/6.4.1',
'reference' => '1731999c38ad73e9593177e016f02aa815ed4dca',
'pretty_version' => 'dev-release/6.5.0',
'version' => 'dev-release/6.5.0',
'reference' => '75ec0cbc31ee105f66684b10fb0433b44b3e58e9',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down
5 changes: 5 additions & 0 deletions vendor/woocommerce/subscriptions-core/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** WooCommerce Subscriptions Core Changelog ***

= 7.3.0 - 2024-07-16 =
* Fix - Label improvements on subscription and order page templates.
* Fix - Fixed an issue with subscriptions containing multiple renewal orders to mark a random item as processing, instead of the last order.
* Fix - Prevent errors from invalid subscription objects during customer payment method updates.

= 7.2.0 - 2024-06-13 =
* Fix - label improvement on my subscription page template.
* Fix - Regenerate subscriptions related order caches (renewal, resubscribe, switch) if it's stored as an invalid value to prevent fatal errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
?>
<tr>
<td>
<a href="<?php echo esc_url( $order->get_edit_order_url() ); ?>">
<?php // translators: placeholder is an order number. ?>
<a href="<?php echo esc_url( $order->get_edit_order_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'Edit order number %s', 'woocommerce-subscriptions' ), $order->get_order_number() ) ); ?>">
<?php
// translators: placeholder is an order number.
echo sprintf( esc_html_x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), esc_html( $order->get_order_number() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ public static function update_all_payment_methods_from_subscription( $subscripti
}

$user_subscription = wcs_get_subscription( $subscription_id );

if ( ! $user_subscription instanceof WC_Subscription ) {
continue;
}

// Skip if subscription's current payment method is not supported
if ( ! $user_subscription->payment_method_supports( 'subscription_cancellation' ) ) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WC_Subscriptions_Core_Plugin {
* The version of subscriptions-core library.
* @var string
*/
protected $library_version = '7.2.0'; // WRCS: DEFINED_VERSION.
protected $library_version = '7.3.0'; // WRCS: DEFINED_VERSION.

/**
* The subscription scheduler instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public static function maybe_record_subscription_payment( $order_id, $orders_old
$is_failed_renewal_order = 'failed' === $orders_old_status || wc_string_to_bool( $order->get_meta( WC_Subscription::RENEWAL_FAILED_META_KEY, true ) );
$is_failed_renewal_order = apply_filters( 'woocommerce_subscriptions_is_failed_renewal_order', $is_failed_renewal_order, $order_id, $orders_old_status );

if ( $order_needed_payment ) {
// Subscription will be activated only if this is the last renewal order of the subscription.
if ( $order_needed_payment && wcs_is_order_last_renewal_of_subscription( $order, $subscription ) ) {
$subscription->payment_complete();
$was_activated = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ function wcs_order_contains_renewal( $order ) {
return apply_filters( 'woocommerce_subscriptions_is_renewal_order', $is_renewal, $order );
}

/**
* Determines if a given order is the subscription's latest renewal order.
*
* @param $order WC_Order The order object.
* @param $subscription WC_Subscription The subscription object.
* @return bool Whether the order is the latest renewal order of the provided subscription.
*/
function wcs_is_order_last_renewal_of_subscription( $order, $subscription ) {
$last_renewal_order = wcs_get_last_renewal_order( $subscription );
return $last_renewal_order && $last_renewal_order->get_id() === $order->get_id();
}

/**
* Checks the cart to see if it contains a subscription product renewal.
*
Expand Down Expand Up @@ -128,10 +140,7 @@ function wcs_get_subscriptions_for_renewal_order( $order ) {
*/
function wcs_get_last_non_early_renewal_order( $subscription ) {
$last_non_early_renewal = false;
$renewal_orders = $subscription->get_related_orders( 'all', 'renewal' );

// We need the orders sorted by the date they were created, with the newest first.
wcs_sort_objects( $renewal_orders, 'date_created', 'descending' );
$renewal_orders = wcs_get_renewal_orders_sorted_by( $subscription, 'date_created' );

foreach ( $renewal_orders as $renewal_order ) {
if ( ! wcs_order_contains_early_renewal( $renewal_order ) ) {
Expand All @@ -143,6 +152,34 @@ function wcs_get_last_non_early_renewal_order( $subscription ) {
return $last_non_early_renewal;
}

/**
* Get the last renewal order (early renewals included).
*
* @param WC_Subscription $subscription The subscription object.
* @return WC_Order|bool The last non-early renewal order, otherwise false.
*/
function wcs_get_last_renewal_order( $subscription ) {
$renewal_orders = wcs_get_renewal_orders_sorted_by( $subscription, 'date_created' );
return $renewal_orders ? reset( $renewal_orders ) : false;
}

/**
* Gets the renewal orders for a subscription, sorted by the specified property.
*
* @param WC_Subscription $subscription The subscription object.
* @param string $sort_by The subscription property to sort by.
* @param string $order Optional. The sort order to sort by. Default is 'descending'.
*
* @return WC_Order[] The subscriptions renewal orders sorted.
*/
function wcs_get_renewal_orders_sorted_by( $subscription, $sort_by, $order = 'descending' ) {
$renewal_orders = $subscription->get_related_orders( 'all', 'renewal' );

wcs_sort_objects( $renewal_orders, $sort_by, $order );

return $renewal_orders;
}

/**
* Checks if manual renewals are required - automatic renewals are disabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<?php foreach ( $subscriptions as $subscription_id => $subscription ) : ?>
<tr class="order woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $subscription->get_status() ); ?>">
<td class="subscription-id order-number woocommerce-orders-table__cell woocommerce-orders-table__cell-subscription-id woocommerce-orders-table__cell-order-number" data-title="<?php esc_attr_e( 'ID', 'woocommerce-subscriptions' ); ?>">
<a href="<?php echo esc_url( $subscription->get_view_order_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'View subscription number %s', 'woocommerce' ), $subscription->get_order_number() ) ) ?>">
<?php // translators: placeholder is a subscription number. ?>
<a href="<?php echo esc_url( $subscription->get_view_order_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'View subscription number %s', 'woocommerce-subscriptions' ), $subscription->get_order_number() ) ) ?>">
<?php echo esc_html( sprintf( _x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), $subscription->get_order_number() ) ); ?>
</a>
<?php do_action( 'woocommerce_my_subscriptions_after_subscription_id', $subscription ); ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author Prospress
* @category WooCommerce Subscriptions/Templates
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.2
* @version 7.3.0 - Migrated from WooCommerce Subscriptions v2.6.2
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -40,7 +40,8 @@

?><tr class="order woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?>">
<td class="order-number woocommerce-orders-table__cell woocommerce-orders-table__cell-order-number" data-title="<?php esc_attr_e( 'Order Number', 'woocommerce-subscriptions' ); ?>">
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php // translators: placeholder is an order number. ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'View order number %s', 'woocommerce-subscriptions' ), $order->get_order_number() ) ) ?>">
<?php echo sprintf( esc_html_x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), esc_html( $order->get_order_number() ) ); ?>
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author Prospress
* @category WooCommerce Subscriptions/Templates
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
* @version 7.3.0 - Migrated from WooCommerce Subscriptions v2.6.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -29,7 +29,8 @@
<?php foreach ( $subscriptions as $subscription_id => $subscription ) : ?>
<tr class="order woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $subscription->get_status() ); ?>">
<td class="subscription-id order-number woocommerce-orders-table__cell woocommerce-orders-table__cell-subscription-id woocommerce-orders-table__cell-order-number" data-title="<?php esc_attr_e( 'ID', 'woocommerce-subscriptions' ); ?>">
<a href="<?php echo esc_url( $subscription->get_view_order_url() ); ?>">
<?php // translators: placeholder is a subscription number. ?>
<a href="<?php echo esc_url( $subscription->get_view_order_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'View subscription number %s', 'woocommerce-subscriptions' ), $subscription->get_order_number() ) ) ?>">
<?php echo sprintf( esc_html_x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), esc_html( $subscription->get_order_number() ) ); ?>
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Author: Automattic
* Author URI: https://woocommerce.com/
* Requires WP: 5.6
* Version: 7.2.0
* Version: 7.3.0
*/
Loading

0 comments on commit b2a4dd8

Please sign in to comment.