WC_Settings_Accounts::outputpublicWC 1.0

Output the HTML for the settings.

Method of the class: WC_Settings_Accounts{}

No Hooks.

Returns

null. Nothing (null).

Usage

$WC_Settings_Accounts = new WC_Settings_Accounts();
$WC_Settings_Accounts->output();

WC_Settings_Accounts::output() code WC 10.5.0

public function output() {
	parent::output();

	// The following code toggles disabled state on the account options based on other values.
	$script =
		'
		// Move tooltips to label element. This is not possible through the settings field API so this is a workaround
		// until said API is refactored.
		document.querySelectorAll("input[disabled-tooltip]").forEach(function(element) {
			const label = element.closest("label");
			label.setAttribute("disabled-tooltip", element.getAttribute("disabled-tooltip"));
		});

		// This handles settings that are enabled/disabled based on other settings.
		const checkboxes = [
			document.getElementById("woocommerce_enable_signup_and_login_from_checkout"),
			document.getElementById("woocommerce_enable_myaccount_registration"),
			document.getElementById("woocommerce_enable_delayed_account_creation"),
			document.getElementById("woocommerce_enable_signup_from_checkout_for_subscriptions")
		];
		const inputs = [
			document.getElementById("woocommerce_registration_generate_username"),
			document.getElementById("woocommerce_registration_generate_password")
		];
		checkboxes.forEach(cb => cb && cb.addEventListener("change", function() {
			const isChecked = checkboxes.some(cb => cb && cb.checked);
			inputs.forEach(input => {
				if ( ! input ) {
					return;
				}
				input.disabled = !isChecked;
			});
		}));
		checkboxes[0].dispatchEvent(new Event("change")); // Initial state

		// Tracks for customize link.
		if ( typeof window?.wcTracks?.recordEvent === "function" ) {
			const customizeLink = document.querySelector("a.delayed-account-creation-customize-link");
			if ( customizeLink ) {
				customizeLink.addEventListener("click", function() {
					window.wcTracks.recordEvent("delayed_account_creation_customize_link_clicked");
				});
			}
		}
	';

	// If the checkout block is not default, delayed account creation is always disabled. Otherwise its based on other settings.
	if ( CartCheckoutUtils::is_checkout_block_default() ) {
		$script .=
			'
			// Guest checkout should toggle off some options.
			const guestCheckout = document.getElementById("woocommerce_enable_guest_checkout");

			if ( guestCheckout ) {
				guestCheckout.addEventListener("change", function() {
					const isChecked = this.checked;
					const input = document.getElementById("woocommerce_enable_delayed_account_creation");
					if ( ! input ) {
						return;
					}
					input.disabled = !isChecked;
				});
				guestCheckout.dispatchEvent(new Event("change")); // Initial state
			}
		';
	}

	$handle = 'wc-admin-settings-accounts';
	wp_register_script( $handle, '', array(), WC_VERSION, array( 'in_footer' => true ) );
	wp_enqueue_script( $handle );
	wp_add_inline_script( $handle, $script );
}