Skip to content
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

feat(ras): add post checkout ras settings #3533

Merged
merged 8 commits into from
Nov 8, 2024
5 changes: 5 additions & 0 deletions includes/class-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ function ( $item ) {
[],
$cart_item_data
);

// Set checkout registration flag if user is not logged in.
if ( ! is_user_logged_in() && class_exists( '\Newspack_Blocks\Modal_Checkout' ) ) {
\Newspack_Blocks\Modal_Checkout::set_checkout_registration_flag();
}
}

$query_args = [];
Expand Down
40 changes: 40 additions & 0 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ private static function get_settings_config() {
'contact_email_address' => Emails::get_reply_to_email(),
'woocommerce_registration_required' => false,
'woocommerce_checkout_privacy_policy_text' => self::get_checkout_privacy_policy_text(),
'woocommerce_post_checkout_success_text' => self::get_post_checkout_success_text(),
'woocommerce_post_checkout_registration_success_text' => self::get_post_checkout_registration_success_text(),
];

/**
Expand Down Expand Up @@ -2401,5 +2403,43 @@ public static function get_checkout_privacy_policy_text() {
)
);
}

/**
* Modal checkout success text.
*
* @return string Post checkout success text.
*/
public static function get_post_checkout_success_text() {
return \get_option(
self::OPTIONS_PREFIX . 'woocommerce_post_checkout_success_text',
sprintf(
// Translators: %s is the name of the site.
__(
'Thank you for supporting %s. Your transaction was completed successfully.',
'newspack-plugin'
),
html_entity_decode( get_bloginfo( 'name' ) )
)
);
}

/**
* Modal checkout registration success text.
*
* @return string Post checkout registration success text.
*/
public static function get_post_checkout_registration_success_text() {
return \get_option(
self::OPTIONS_PREFIX . 'woocommerce_post_checkout_registration_success_text',
sprintf(
// Translators: %s is the name of the site.
__(
'Thank you for supporting %s. Your account has been created, and your transaction was completed successfully.',
'newspack-plugin'
),
html_entity_decode( get_bloginfo( 'name' ) )
)
);
}
}
Reader_Activation::init();
56 changes: 40 additions & 16 deletions src/wizards/engagement/views/reader-activation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* WordPress dependencies
*/
import apiFetch from '@wordpress/api-fetch';
import { ExternalLink } from '@wordpress/components';
import { ExternalLink, TextareaControl, ToggleControl } from '@wordpress/components';
import { useEffect, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

Expand All @@ -14,6 +14,7 @@ import {
ActionCard,
Button,
Card,
Grid,
Notice,
PluginInstaller,
SectionHeader,
Expand Down Expand Up @@ -431,27 +432,48 @@ export default withWizardScreen( ( { wizardApiFetch } ) => {

<SectionHeader title={ __( 'Checkout Configuration', 'newspack-plugin' ) } />

<ActionCard
title={ __(
'Prompt logged out readers to sign in or register a new account before checkout',
'newspack-plugin'
) }
description={ __(
'Require logged out readers to sign in or register a new account before proceeding to checkout.',
<ToggleControl
label={ __(
'Require sign in or create account before checkout',
'newspack-plugin'
) }
toggleChecked={ config.woocommerce_registration_required }
toggleOnChange={ value => updateConfig( 'woocommerce_registration_required', value ) }
/>
<TextControl
label={ __( 'Checkout privacy policy text', 'newspack-plugin' ) }
help={ __(
'The privacy policy text to display at time of checkout for existing users. This will not show up unless a privacy page is set.',
'Prompt users who are not logged in to sign in or register a new account before proceeding to checkout. When disabled, an account will automatically be created with the email address used at checkout.',
'newspack-plugin'
) }
{ ...getSharedProps( 'woocommerce_checkout_privacy_policy_text', 'text' ) }
checked={ config.woocommerce_registration_required }
onChange={ value => updateConfig( 'woocommerce_registration_required', value ) }
/>

<Grid>
<TextareaControl
label={ __( 'Post-checkout success message', 'newspack-plugin' ) }
help={ __(
'The success message to display to readers after completing checkout.',
'newspack-plugin'
) }
{ ...getSharedProps( 'woocommerce_post_checkout_success_text', 'text' ) }
/>
{ ! config.woocommerce_registration_required && (
<TextareaControl
label={ __( 'Post-checkout registration success message', 'newspack-plugin' ) }
help={ __(
'The success message to display to new readers that have an account automatically created after completing checkout.',
'newspack-plugin'
) }
{ ...getSharedProps( 'woocommerce_post_checkout_registration_success_text', 'text' ) }
/>
) }
</Grid>
<Grid>
<TextareaControl
label={ __( 'Checkout privacy policy text', 'newspack-plugin' ) }
help={ __(
'The privacy policy text to display at time of checkout for existing users. This will not show up unless a privacy page is set.',
'newspack-plugin'
) }
{ ...getSharedProps( 'woocommerce_checkout_privacy_policy_text', 'text' ) }
/>
</Grid>
<div className="newspack-buttons-card">
<Button
isPrimary
Expand Down Expand Up @@ -482,6 +504,8 @@ export default withWizardScreen( ( { wizardApiFetch } ) => {
metadata_prefix: config.metadata_prefix,
woocommerce_registration_required: config.woocommerce_registration_required,
woocommerce_checkout_privacy_policy_text: config.woocommerce_checkout_privacy_policy_text,
woocommerce_post_checkout_success_text: config.woocommerce_post_checkout_success_text,
woocommerce_post_checkout_registration_success_text: config.woocommerce_post_checkout_registration_success_text,
} );
} }
disabled={ inFlight }
Expand Down