Enhancement: Update account creation settings wording (#48556)

* Reword and reorganise existing account settings

* Disable account creation options if toggled off

* Toggle disabled state of related options

* Update settings crud tests

* changelog

* Hide based on subscriptions checkbox also
This commit is contained in:
Mike Jolley 2024-07-02 12:37:15 +01:00 committed by GitHub
parent fae23f0906
commit dabc29c04e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 113 additions and 49 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Updated account settings descriptions for added clarity

View File

@ -5173,6 +5173,10 @@ img.help_tip {
float: none;
}
td.disabled {
opacity: 0.5;
}
fieldset {
margin-top: 4px;
@ -5255,6 +5259,13 @@ img.help_tip {
.wc_emails_wrapper {
padding: 0 15px 10px 0;
}
legend {
font-weight: 700;
line-height: 1.4;
padding: 5px 0 0;
margin: 0 0 8px !important;
}
}
.wc-shipping-zone-settings {

View File

@ -47,7 +47,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
if ( empty( self::$settings ) ) {
$settings = array();
include_once dirname( __FILE__ ) . '/settings/class-wc-settings-page.php';
include_once __DIR__ . '/settings/class-wc-settings-page.php';
$settings[] = include __DIR__ . '/settings/class-wc-settings-general.php';
$settings[] = include __DIR__ . '/settings/class-wc-settings-products.php';
@ -153,7 +153,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Get tabs for the settings page.
$tabs = apply_filters( 'woocommerce_settings_tabs_array', array() );
include dirname( __FILE__ ) . '/views/html-admin-settings.php';
include __DIR__ . '/views/html-admin-settings.php';
}
/**
@ -514,11 +514,19 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
$visibility_class[] = $value['row_class'];
}
$must_disable = $value['disabled'] ?? false;
if ( $must_disable ) {
$visibility_class[] = 'disabled';
}
$container_class = implode( ' ', $visibility_class );
$must_disable = $value['disabled'] ?? false;
$has_title = isset( $value['title'] ) && '' !== $value['title'];
$has_legend = isset( $value['legend'] ) && '' !== $value['legend'];
if ( ! isset( $value['checkboxgroup'] ) || 'start' === $value['checkboxgroup'] ) {
$has_tooltip = isset( $value['tooltip'] ) && '' !== $value['tooltip'];
$has_tooltip = isset( $value['tooltip'] ) && '' !== $value['tooltip'];
$tooltip_container_class = $has_tooltip ? 'with-tooltip' : '';
?>
<tr class="<?php echo esc_attr( $container_class ); ?>">
@ -535,9 +543,9 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
<?php
}
if ( ! empty( $value['title'] ) ) {
if ( $has_title || $has_legend ) {
?>
<legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
<legend class="<?php echo $has_legend ? '' : 'screen-reader-text'; ?>"><span><?php echo esc_html( $has_legend ? $value['legend'] : $value['title'] ); ?></span></legend>
<?php
}
@ -550,7 +558,6 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
type="checkbox"
class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
value="1"
<?php disabled( $value['disabled'] ?? false ); ?>
<?php checked( $option_value, 'yes' ); ?>
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
/> <?php echo $description; // WPCS: XSS ok. ?>

View File

@ -50,8 +50,9 @@ class WC_Settings_Accounts extends WC_Settings_Page {
'id' => 'account_registration_options',
),
array(
'title' => __( 'Guest checkout', 'woocommerce' ),
'desc' => __( 'Allow customers to place orders without an account', 'woocommerce' ),
'title' => __( 'Checkout', 'woocommerce' ),
'desc' => __( 'Enable guest checkout (recommended)', 'woocommerce' ),
'desc_tip' => __( 'Allows customers to checkout without an account.', 'woocommerce' ),
'id' => 'woocommerce_enable_guest_checkout',
'default' => 'yes',
'type' => 'checkbox',
@ -60,7 +61,7 @@ class WC_Settings_Accounts extends WC_Settings_Page {
),
array(
'title' => __( 'Login', 'woocommerce' ),
'desc' => __( 'Allow customers to log into an existing account during checkout', 'woocommerce' ),
'desc' => __( 'Enable log-in during checkout', 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder',
'default' => 'no',
'type' => 'checkbox',
@ -69,31 +70,38 @@ class WC_Settings_Accounts extends WC_Settings_Page {
),
array(
'title' => __( 'Account creation', 'woocommerce' ),
'desc' => __( 'Allow customers to create an account during checkout', 'woocommerce' ),
'desc' => __( 'During checkout', 'woocommerce' ),
'desc_tip' => __( 'Customers can create an account before placing their order.', 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'legend' => __( 'Allow customers to create an account:', 'woocommerce' ),
'autoload' => false,
),
array(
'title' => __( 'Account creation', 'woocommerce' ),
'desc' => __( 'On "My account" page', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Account creation options', 'woocommerce' ),
'desc' => __( 'Use email address as account login (recommended)', 'woocommerce' ),
'desc_tip' => __( 'If unchecked, customers will need to set a username during account creation.', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Allow customers to create an account on the "My account" page', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
'autoload' => false,
),
array(
'desc' => __( 'When creating an account, automatically generate an account username for the customer based on their name, surname or email', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'autoload' => false,
),
array(
'desc' => __( 'When creating an account, send the new user a link to set their password', 'woocommerce' ),
'title' => __( 'Account creation options', 'woocommerce' ),
'desc' => __( 'Send password setup link (recommended)', 'woocommerce' ),
'desc_tip' => __( 'New customers receive an email to set up their password.', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password',
'default' => 'yes',
'type' => 'checkbox',
@ -118,7 +126,7 @@ class WC_Settings_Accounts extends WC_Settings_Page {
'id' => 'woocommerce_erasure_request_removes_download_data',
'type' => 'checkbox',
'default' => 'no',
'checkboxgroup' => 'end',
'checkboxgroup' => '',
'autoload' => false,
),
array(
@ -127,7 +135,7 @@ class WC_Settings_Accounts extends WC_Settings_Page {
'desc_tip' => __( 'Adds an option to the orders screen for removing personal data in bulk. Note that removing personal data cannot be undone.', 'woocommerce' ),
'id' => 'woocommerce_allow_bulk_remove_personal_data',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'checkboxgroup' => 'end',
'default' => 'no',
'autoload' => false,
),
@ -229,10 +237,49 @@ class WC_Settings_Accounts extends WC_Settings_Page {
),
);
return apply_filters(
'woocommerce_' . $this->id . '_settings',
$account_settings
);
/**
* Filter account settings.
*
* @hook woocommerce_account_settings
* @since 3.5.0
* @param array $account_settings Account settings.
*/
return apply_filters( 'woocommerce_' . $this->id . '_settings', $account_settings );
}
/**
* Output the HTML for the settings.
*/
public function output() {
parent::output();
// The following code toggles disabled state on the account options based on other values.
?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = [
document.getElementById("woocommerce_enable_signup_and_login_from_checkout"),
document.getElementById("woocommerce_enable_myaccount_registration"),
document.getElementById("woocommerce_enable_signup_from_checkout_for_subscriptions")
];
const inputs = [
document.getElementById("woocommerce_registration_generate_username"),
document.getElementById("woocommerce_registration_generate_password")
];
function updateInputs() {
const isChecked = checkboxes.some(cb => cb && cb.checked);
inputs.forEach(input => {
input.disabled = !isChecked;
input.closest('td').classList.toggle("disabled", !isChecked);
});
}
checkboxes.forEach(cb => cb.addEventListener('change', updateInputs));
updateInputs(); // Initial state
});
</script>
<?php
}
}

View File

@ -1334,9 +1334,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.arrayContaining( [
expect.objectContaining( {
id: 'woocommerce_enable_guest_checkout',
label: 'Guest checkout',
description:
'Allow customers to place orders without an account',
label: 'Checkout',
description: 'Enable guest checkout (recommended)',
type: 'checkbox',
default: 'yes',
value: 'yes',
@ -1348,8 +1347,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.objectContaining( {
id: 'woocommerce_enable_checkout_login_reminder',
label: 'Login',
description:
'Allow customers to log into an existing account during checkout',
description: 'Enable log-in during checkout',
type: 'checkbox',
default: 'no',
value: 'no',
@ -1361,8 +1359,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.objectContaining( {
id: 'woocommerce_enable_signup_and_login_from_checkout',
label: 'Account creation',
description:
'Allow customers to create an account during checkout',
description: 'During checkout',
type: 'checkbox',
default: 'no',
value: 'no',
@ -1373,9 +1370,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.arrayContaining( [
expect.objectContaining( {
id: 'woocommerce_enable_myaccount_registration',
label: '',
description:
'Allow customers to create an account on the "My account" page',
label: 'Account creation',
description: 'On "My account" page',
type: 'checkbox',
default: 'no',
value: 'no',
@ -1386,9 +1382,9 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.arrayContaining( [
expect.objectContaining( {
id: 'woocommerce_registration_generate_username',
label: '',
label: 'Account creation options',
description:
'When creating an account, automatically generate an account username for the customer based on their name, surname or email',
'Use email address as account login (recommended)',
type: 'checkbox',
default: 'yes',
value: 'yes',
@ -1399,9 +1395,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.arrayContaining( [
expect.objectContaining( {
id: 'woocommerce_registration_generate_password',
label: '',
description:
'When creating an account, send the new user a link to set their password',
label: 'Account creation options',
description: 'Send password setup link (recommended)',
type: 'checkbox',
default: 'yes',
value: 'yes',