Skip to content

Commit 6425dbf

Browse files
dkooCopilotthomasguillotchickenn00dlesemantic-release-bot
authored
feat(my-account): new layout for single subscription pages (#4425)
* feat(my-account): custom subscription details page for Newspack sites * feat: show status badge * feat: start "renew subscription" button for inactive subs * style: unbold grand total if not showing subtotals * feat: custom order again buttons * fix: show order-again button in subscription header only for expired/cancelled status * fix: restore p.order-again element * fix: improper placement of conditional * fix: remove duplicate button class name * Update includes/plugins/woocommerce/my-account/templates/v1/subscription-header.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: esc_html_e instead of _e * fix: esc_html_e instead of _e * Update includes/plugins/woocommerce/my-account/class-my-account-ui-v1.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: global namespace WCS_Staging class * fix: add missing template file * fix: remove unneeded template file * fix: remove no-longer-used variable * Update includes/plugins/woocommerce/my-account/templates/v1/related-orders.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: only show order-again button in expired subscription headers * fix: remove .button class from order-again button * feat(newspack-ui): update demo * feat(newspack-ui): update notice * feat(my-account): reorganise subscription header * feat(newspack-ui): adjust margin for text + icon buttons * fix: full-width header buttons instead of dropdown at mobile viewports * fix: better targeting for header dropdown * fix: show "renew subscription" for cancelled subs sans resubscribe action * fix: set header badge class based on status * feat: replace My Account notices w/ Newspack UI snackbars * style: remove top margin from switch button in header * feat(subscriptions): update table padding * feat(newspack-ui): partially update snackbar * feat: update table * fix: snackbar autohide behavior * fix: snackbar notices behavior * feat(newspack-ui): small tweaks to snackbar * fix(memberships): allow free trial members to comment (#4428) This PR addresses an issue where we were incorrectly filtering memberships with an "active" status, omitting free trial memberships. The Memberships::$active_statuses array uses a hyphen rather than an underscore for `free_trial`, which the wc_memberships_get_user_memberships methods requires. * chore(release): 6.29.4 [skip ci] ## [6.29.4](v6.29.3...v6.29.4) (2026-01-28) ### Bug Fixes * **memberships:** allow free trial members to comment ([#4428](#4428)) ([32d455e](32d455e)) * fix(subscriptions): skip free trial tweak during switches (#4432) * chore(release): 6.29.5 [skip ci] ## [6.29.5](v6.29.4...v6.29.5) (2026-01-29) ### Bug Fixes * **subscriptions:** skip free trial tweak during switches ([#4432](#4432)) ([4277a3c](4277a3c)) * feat: Add My Account button block (#4409) * chore: update translation files [skip ci] * feat(content-gate): support new metering schema (#4419) * chore: update translation files [skip ci] * chore: deprecate circle ci (#4413) * chore(github-actions): fix reusable workflow reference * fix(collections): hide indicator for unpublished collections (#4434) * fix: snackbar slide in-out position * Update src/newspack-ui/js/notices.js Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * refactor: newspackUI public API via modules * feat: add newspack_ui_notice_is_urgent to make notices dismissmible --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Thomas Guillot <thomas@automattic.com> Co-authored-by: Rasmy Nguyen <raz@automattic.com> Co-authored-by: matticbot <semantic-release-bot@martynus.net> Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> Co-authored-by: Laurel <laurel.fulford@automattic.com> Co-authored-by: matticbot <sysops+ghmatticbot@automattic.com> Co-authored-by: Ramon Corrales <rbcorrales@users.noreply.github.com>
1 parent 8de3526 commit 6425dbf

32 files changed

Lines changed: 1171 additions & 155 deletions

includes/class-newspack-ui-icons.php

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

includes/class-newspack-ui.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public static function return_demo_content() {
428428
<div class="newspack-ui__dropdown">
429429
<button class="newspack-ui__dropdown__toggle newspack-ui__button newspack-ui__button--icon newspack-ui__button--ghost">
430430
<?php Newspack_UI_Icons::print_svg( 'more' ); ?>
431-
<span class="screen-reader-text">More</span>
431+
<span class="screen-reader-text"><?php esc_html_e( 'More', 'newspack-plugin' ); ?></span>
432432
</button>
433433
<div class="newspack-ui__dropdown__content">
434434
<ul>
@@ -448,7 +448,7 @@ public static function return_demo_content() {
448448
<div class="newspack-ui__dropdown">
449449
<button class="newspack-ui__dropdown__toggle newspack-ui__button newspack-ui__button--icon newspack-ui__button--ghost">
450450
<?php Newspack_UI_Icons::print_svg( 'more' ); ?>
451-
<span class="screen-reader-text">More</span>
451+
<span class="screen-reader-text"><?php esc_html_e( 'More', 'newspack-plugin' ); ?></span>
452452
</button>
453453
<div class="newspack-ui__dropdown__content">
454454
<ul>
@@ -518,15 +518,17 @@ public static function return_demo_content() {
518518
</div>
519519
</div>
520520
<button id="show-snackbar-example" class="newspack-ui__button newspack-ui__button--primary">Show snackbar</button>
521-
<div id="snackbar-example" class="newspack-ui__snackbar newspack-ui__snackbar--top-right newspack-ui__snackbar--success">
522-
This is a snackbar message
521+
<div class="newspack-ui__snackbar newspack-ui__snackbar--top-right">
522+
<div id="snackbar-example" class="newspack-ui__snackbar__item newspack-ui__snackbar__item--success" data-autohide="true">
523+
<div class="newspack-ui__snackbar__content">This is a snackbar message</div>
524+
</div>
523525
</div>
524526
<script>
525527
( function() {
526528
const snackbar = document.getElementById( 'snackbar-example' );
527529
const button = document.getElementById( 'show-snackbar-example' );
528530
button.addEventListener( 'click', function() {
529-
snackbar.classList.add( 'active' );
531+
newspackUI.notices.openNotice( snackbar, false );
530532
} );
531533
} )();
532534
</script>
@@ -761,7 +763,7 @@ public static function return_demo_content() {
761763
<h3>Dropdown buttons</h3>
762764
<div class="newspack-ui__dropdown">
763765
<button class="newspack-ui__button newspack-ui__button--secondary newspack-ui__dropdown__toggle">
764-
<span>More</span>
766+
<span><?php esc_html_e( 'More', 'newspack-plugin' ); ?></span>
765767
<?php Newspack_UI_Icons::print_svg( 'more' ); ?>
766768
</button>
767769
<div class="newspack-ui__dropdown__content">

includes/plugins/woocommerce-subscriptions/class-woocommerce-subscriptions.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,29 @@ function( $subscription ) {
297297
}
298298
return $subscriptions;
299299
}
300+
301+
/**
302+
* Get the product ID for a subscription.
303+
*
304+
* @param WC_Subscription|int $subscription The subscription object or ID.
305+
*
306+
* @return int|false The product ID, or false if no product is found.
307+
*/
308+
public static function get_subscription_product_id( $subscription ) {
309+
if ( ! is_a( $subscription, 'WC_Subscription' ) ) {
310+
$subscription = \wcs_get_subscription( $subscription );
311+
}
312+
if ( ! $subscription ) {
313+
return false;
314+
}
315+
$product_id = false;
316+
foreach ( $subscription->get_items() as $item ) {
317+
$product_id = \wcs_get_canonical_product_id( $item );
318+
if ( $product_id ) {
319+
break;
320+
}
321+
}
322+
return $product_id;
323+
}
300324
}
301325
WooCommerce_Subscriptions::init();

includes/plugins/woocommerce-subscriptions/group-subscription/class-group-subscription-api.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Group_Subscription_API {
1818
* Initialize hooks.
1919
*/
2020
public static function init() {
21-
add_action( 'rest_api_init', [ __CLASS__, 'register_routes' ] );
21+
\add_action( 'rest_api_init', [ __CLASS__, 'register_routes' ] );
2222
}
2323

2424
/**
@@ -84,7 +84,7 @@ public static function register_routes() {
8484
* Permission callback for the add_members route.
8585
*/
8686
public static function permission_callback() {
87-
return current_user_can( 'manage_woocommerce' );
87+
return \current_user_can( 'manage_woocommerce' );
8888
}
8989

9090
/**
@@ -126,14 +126,14 @@ public static function api_search_users( $request ) {
126126
)
127127
);
128128
$exclude = array_values( array_unique( array_merge( $exclude, array_column( $query1, 'ID' ) ) ) );
129-
$query2 = get_users(
129+
$query2 = \get_users(
130130
/**
131131
* Filter the user query args for searching for group subscription users.
132132
*
133133
* @param array $query_args Query args.
134134
* @param string $query_type Query type: main_query or meta_query.
135135
*/
136-
apply_filters(
136+
\apply_filters(
137137
'newspack_group_subscription_user_query_args',
138138
[
139139
'fields' => [ 'ID', 'user_email' ],

includes/plugins/woocommerce-subscriptions/group-subscription/class-group-subscription-settings.php

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class Group_Subscription_Settings {
3131
*/
3232
public static function init() {
3333
// Add Group Subscription options to subscription and variable subscription product admin pages.
34-
add_filter( 'newspack_custom_product_options', [ __CLASS__, 'add_custom_product_options' ] );
35-
add_filter( 'newspack_custom_product_pricing_options', [ __CLASS__, 'add_custom_product_pricing_options' ] );
34+
\add_filter( 'newspack_custom_product_options', [ __CLASS__, 'add_custom_product_options' ] );
35+
\add_filter( 'newspack_custom_product_pricing_options', [ __CLASS__, 'add_custom_product_pricing_options' ] );
3636

3737
// Add Group Subscription options to subscription admin pages.
38-
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_enqueue_scripts' ] );
39-
add_action( 'add_meta_boxes', [ __CLASS__, 'add_group_subscription_meta_box' ], 26, 2 );
40-
add_action( 'woocommerce_process_shop_order_meta', [ __CLASS__, 'save_group_subscription_meta' ], 10, 2 );
41-
add_action( 'wp_ajax_newspack_group_subscription_search_users', [ __CLASS__, 'ajax_search_users' ] );
38+
\add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_enqueue_scripts' ] );
39+
\add_action( 'add_meta_boxes', [ __CLASS__, 'add_group_subscription_meta_box' ], 26, 2 );
40+
\add_action( 'woocommerce_process_shop_order_meta', [ __CLASS__, 'save_group_subscription_meta' ], 10, 2 );
41+
\add_action( 'wp_ajax_newspack_group_subscription_search_users', [ __CLASS__, 'ajax_search_users' ] );
4242
}
4343

4444
/**
@@ -48,13 +48,13 @@ public static function admin_enqueue_scripts() {
4848
if ( ! function_exists( 'wcs_get_page_screen_id' ) ) {
4949
return;
5050
}
51-
$screen = get_current_screen();
51+
$screen = \get_current_screen();
5252
$is_subscription_screen = in_array(
5353
$screen->id,
5454
[
5555
'edit-shop_subscription',
5656
'shop_subscription',
57-
wcs_get_page_screen_id( 'shop_subscription' ),
57+
\wcs_get_page_screen_id( 'shop_subscription' ),
5858
],
5959
true
6060
);
@@ -166,30 +166,6 @@ public static function get_product_settings( $product ) {
166166
return apply_filters( 'newspack_group_subscription_product_settings', $settings, $product );
167167
}
168168

169-
/**
170-
* Get the product ID for a subscription.
171-
*
172-
* @param WC_Subscription|int $subscription The subscription object or ID.
173-
*
174-
* @return int|false The product ID, or false if no product is found.
175-
*/
176-
public static function get_subscription_product_id( $subscription ) {
177-
if ( ! is_a( $subscription, 'WC_Subscription' ) ) {
178-
$subscription = \wcs_get_subscription( $subscription );
179-
}
180-
if ( ! $subscription ) {
181-
return false;
182-
}
183-
$product_id = false;
184-
foreach ( $subscription->get_items() as $item ) {
185-
$product_id = \wcs_get_canonical_product_id( $item );
186-
if ( $product_id ) {
187-
break;
188-
}
189-
}
190-
return $product_id;
191-
}
192-
193169
/**
194170
* Get the group subscription settings for a subscription.
195171
*
@@ -207,7 +183,7 @@ public static function get_subscription_settings( $subscription ) {
207183
if ( ! $subscription ) {
208184
return self::DEFAULT_SETTINGS;
209185
}
210-
$product_id = self::get_subscription_product_id( $subscription );
186+
$product_id = WooCommerce_Subscriptions::get_subscription_product_id( $subscription );
211187
$settings = self::get_product_settings( $product_id );
212188
$settings['enabled'] = $subscription->get_meta( self::GROUP_SUBSCRIPTION_META_PREFIX . 'enabled', true ) ? \wc_string_to_bool( $subscription->get_meta( self::GROUP_SUBSCRIPTION_META_PREFIX . 'enabled', true ) ) : $settings['enabled'];
213189
$settings['limit'] = (int) $subscription->get_meta( self::GROUP_SUBSCRIPTION_META_PREFIX . 'limit', true ) ?: $settings['limit']; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
@@ -286,7 +262,7 @@ public static function add_group_subscription_options( $subscription ) {
286262
return;
287263
}
288264
$settings = self::get_subscription_settings( $subscription );
289-
$product = \wc_get_product( self::get_subscription_product_id( $subscription ) );
265+
$product = \wc_get_product( WooCommerce_Subscriptions::get_subscription_product_id( $subscription ) );
290266
$members = Group_Subscription::get_members( $subscription );
291267
?>
292268
<div class="newspack-group-subscription--container" data-subscription-id="<?php echo \esc_attr( $subscription->get_id() ); ?>">

includes/plugins/woocommerce/my-account/class-my-account-ui-v1.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static function init() {
4747
\add_action( 'woocommerce_after_save_address_validation', [ __CLASS__, 'handle_delete_address_submission' ], 10, 4 );
4848
\add_filter( 'woocommerce_address_to_edit', [ __CLASS__, 'reorder_address_fields' ], PHP_INT_MAX, 2 );
4949
\add_action( 'woocommerce_account_content', [ __CLASS__, 'render_content_around_shortcode' ], 0 );
50+
\add_action( 'newspack_subscription_header', [ __CLASS__, 'render_subscription_header' ] );
51+
\add_filter( 'woocommerce_my_subscriptions_payment_method', [ __CLASS__, 'formatted_payment_method' ], 10, 2 );
5052
}
5153

5254
/**
@@ -168,6 +170,24 @@ public static function wc_get_template( $template, $template_name ) {
168170
return __DIR__ . '/templates/v1/form-edit-address.php';
169171
case 'myaccount/my-subscriptions.php':
170172
return __DIR__ . '/templates/v1/my-subscriptions.php';
173+
case 'myaccount/view-subscription.php':
174+
return __DIR__ . '/templates/v1/view-subscription.php';
175+
case 'myaccount/subscription-details.php':
176+
return __DIR__ . '/templates/v1/subscription-details.php';
177+
case 'myaccount/subscription-totals-table.php':
178+
return __DIR__ . '/templates/v1/subscription-totals-table.php';
179+
case 'myaccount/related-orders.php':
180+
return __DIR__ . '/templates/v1/related-orders.php';
181+
case 'myaccount/related-subscriptions.php':
182+
return __DIR__ . '/templates/v1/related-subscriptions.php';
183+
case 'order/order-again.php':
184+
return __DIR__ . '/templates/v1/order-again.php';
185+
case 'notices/error.php':
186+
return __DIR__ . '/templates/v1/notices/error.php';
187+
case 'notices/notice.php':
188+
return __DIR__ . '/templates/v1/notices/notice.php';
189+
case 'notices/success.php':
190+
return __DIR__ . '/templates/v1/notices/success.php';
171191
default:
172192
return $template;
173193
}
@@ -915,5 +935,35 @@ function() use ( $after ) {
915935
);
916936
}
917937
}
938+
939+
/**
940+
* Render subscription actions as a dropdown menu.
941+
*
942+
* @param \WC_Subscription $subscription Subscription.
943+
*/
944+
public static function render_subscription_header( $subscription ) {
945+
if ( ! function_exists( 'is_account_page' ) || ! \is_account_page() ) {
946+
return;
947+
}
948+
$args = [
949+
'actions' => \wcs_get_all_user_actions_for_subscription( $subscription, \get_current_user_id() ),
950+
'subscription' => $subscription,
951+
];
952+
\load_template( __DIR__ . '/templates/v1/subscription-header.php', true, $args );
953+
}
954+
955+
/**
956+
* Format the payment method for the subscription details table.
957+
*
958+
* @param string $payment_method The payment method.
959+
* @param \WC_Subscription $subscription The subscription.
960+
*
961+
* @return string The formatted payment method.
962+
*/
963+
public static function formatted_payment_method( $payment_method, $subscription ) {
964+
// Strip "via" from the payment method (case-insensitive).
965+
$payment_method = str_ireplace( 'via ', '', $payment_method );
966+
return $payment_method;
967+
}
918968
}
919969
My_Account_UI_V1::init();

includes/plugins/woocommerce/my-account/templates/v1/account-settings.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* My Account Account Settings page.
44
* Based on woocommerce/templates/myaccount/form-edit-account.php.
55
*
6-
* @package Newspack
7-
* @version 8.7.0
6+
* @author Newspack
7+
* @category WooCommerce Subscriptions/Templates
8+
* @package Newspack
89
*/
910

1011
namespace Newspack;
@@ -39,13 +40,10 @@
3940
?>
4041

4142
<?php
42-
if ( $message ) :
43-
?>
44-
<div class="newspack-wc-message <?php echo $is_error ? 'newspack-wc-message--error' : ''; ?>">
45-
<p><?php echo \esc_html( $message ); ?></p>
46-
</div>
47-
<?php
48-
endif;
43+
if ( $message ) {
44+
\wc_add_notice( $message, $is_error ? 'error' : 'notice' );
45+
\wc_print_notices();
46+
}
4947
?>
5048

5149
<section id="account-profile">

includes/plugins/woocommerce/my-account/templates/v1/form-edit-address.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* happen. When this occurs the version of the template file will be bumped and
1111
* the readme will list any important changes.
1212
*
13-
* @see https://woocommerce.com/document/template-structure/
14-
* @package WooCommerce\Templates
15-
* @version 9.3.0
13+
* @author Newspack
14+
* @category WooCommerce Subscriptions/Templates
15+
* @package Newspack
1616
*/
1717

1818
defined( 'ABSPATH' ) || exit;

includes/plugins/woocommerce/my-account/templates/v1/my-account.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
/**
33
* My Account page template with no header or footer.
44
*
5-
* @package Newspack
5+
* @author Newspack
6+
* @category WooCommerce Subscriptions/Templates
7+
* @package Newspack
68
*/
79

810
?><!doctype html>

includes/plugins/woocommerce/my-account/templates/v1/navigation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
/**
33
* My Account navigation menu.
44
*
5-
* @package Newspack
5+
* @author Newspack
6+
* @category WooCommerce Subscriptions/Templates
7+
* @package Newspack
68
*/
79

810
use Newspack\Newspack_UI_Icons;

0 commit comments

Comments
 (0)