Skip to content

Commit

Permalink
fix(ras-acc): update limited subscription cart error and modal layout (
Browse files Browse the repository at this point in the history
…#1858)

This PR updates the limited subscription checkout error message and adds a back button to the modal when an error is present
  • Loading branch information
chickenn00dle authored Aug 29, 2024
1 parent 2f16c97 commit 184b06f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions includes/class-modal-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ public static function get_checkout_template( $template ) {
// Trigger checkout error event if there are cart errors.
if ( is_cart() && ! empty( $wc_errors ) ) :
?>
<button class="newspack-ui__button newspack-ui__button--primary newspack-ui__button--wide" id="checkout_error_back" type="submit"><?php esc_html_e( 'Go back', 'newspack-blocks' ); ?></button>
<script>
jQuery( document.body ).trigger( 'checkout_error' );
</script>
Expand Down Expand Up @@ -1064,7 +1065,11 @@ public static function pass_url_param_on_redirect( $location ) {
* @return string
*/
public static function get_subscription_limited_message() {
return __( 'You may only have one subscription of this product at a time.', 'newspack-blocks' );
return sprintf(
// translators: %s: Site name.
__( "You're already a subscriber! You can only have one active subscription at a time. Thank you for supporting %s.", 'newspack-blocks' ),
get_bloginfo( 'name' )
);
}

/**
Expand All @@ -1079,7 +1084,7 @@ public static function woocommerce_cart_product_cannot_be_purchased_message( $me
if ( method_exists( 'WCS_Limiter', 'is_purchasable' ) ) {
$product = \wc_get_product( $product_data->get_id() );
if ( ! \WCS_Limiter::is_purchasable( false, $product ) ) {
$message .= ' ' . self::get_subscription_limited_message();
$message = self::get_subscription_limited_message();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/modal-checkout/checkout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@
margin-top: 0;
}

// stylelint-disable-next-line selector-id-pattern
#checkout_error_back {
margin-bottom: 0;
}

form.checkout .woocommerce-NoticeGroup,
.woocommerce .woocommerce-notices-wrapper {
li div {
Expand All @@ -550,6 +555,7 @@

.woocommerce .woocommerce-notices-wrapper {
margin-bottom: var(--newspack-ui-spacer-5, 24px);
margin-top: 0;
}

.processing {
Expand Down
7 changes: 7 additions & 0 deletions src/modal-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ domReady(
( _, error ) => $( error ).addClass(`${ CLASS_PREFIX }__notice ${ CLASS_PREFIX }__notice--error` )
);
}
const $checkout_error_back = $( '#checkout_error_back' );
if ( $checkout_error_back.length ) {
$checkout_error_back.on( 'click', ev => {
ev.preventDefault();
parent.newspackCloseModalCheckout()
} );
}
setReady();
} );

Expand Down

0 comments on commit 184b06f

Please sign in to comment.