Respect woocommerce_enable_delayed_account_creation at block level
This commit is contained in:
parent
fa6d699d24
commit
dd3981e3eb
|
@ -10,6 +10,7 @@ import {
|
|||
useBlockProps,
|
||||
InspectorControls,
|
||||
} from '@wordpress/block-editor';
|
||||
import { getSetting } from '@woocommerce/settings';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -71,13 +72,18 @@ type EditProps = {
|
|||
export const Edit = ( {
|
||||
attributes,
|
||||
setAttributes,
|
||||
}: EditProps ): JSX.Element => {
|
||||
}: EditProps ): JSX.Element | null => {
|
||||
const className = clsx( 'wc-block-order-confirmation-create-account', {
|
||||
'has-dark-controls': attributes.hasDarkControls,
|
||||
} );
|
||||
const blockProps = useBlockProps( {
|
||||
className,
|
||||
} );
|
||||
const isEnabled = getSetting( 'delayedAccountCreationEnabled', true );
|
||||
|
||||
if ( ! isEnabled ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div { ...blockProps }>
|
||||
|
|
|
@ -12,6 +12,7 @@ if ( class_exists( 'WC_Settings_Accounts', false ) ) {
|
|||
}
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
|
||||
/**
|
||||
* WC_Settings_Accounts.
|
||||
|
@ -263,6 +264,15 @@ class WC_Settings_Accounts extends WC_Settings_Page {
|
|||
),
|
||||
);
|
||||
|
||||
if ( ! Features::is_enabled( 'experimental-blocks' ) ) {
|
||||
$account_settings = array_filter(
|
||||
$account_settings,
|
||||
function ( $setting ) {
|
||||
return 'woocommerce_enable_delayed_account_creation' !== $setting['id'];
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Change settings when using the block based checkout.
|
||||
if ( CartCheckoutUtils::is_checkout_block_default() ) {
|
||||
$account_settings = array_filter(
|
||||
|
|
|
@ -4,6 +4,7 @@ declare( strict_types = 1 );
|
|||
namespace Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation;
|
||||
|
||||
use Automattic\WooCommerce\StoreApi\Utilities\OrderController;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
|
||||
/**
|
||||
* CreateAccount class.
|
||||
|
@ -33,6 +34,15 @@ class CreateAccount extends AbstractOrderConfirmationBlock {
|
|||
return $key ? $script[ $key ] : $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if delayed account creation is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_feature_enabled() {
|
||||
return Features::is_enabled( 'experimental-blocks' ) && get_option( 'woocommerce_enable_delayed_account_creation', 'yes' ) === 'yes';
|
||||
}
|
||||
|
||||
/**
|
||||
* Process posted account form.
|
||||
*
|
||||
|
@ -111,7 +121,7 @@ class CreateAccount extends AbstractOrderConfirmationBlock {
|
|||
* @return string
|
||||
*/
|
||||
protected function render_content( $order, $permission = false, $attributes = [], $content = '' ) {
|
||||
if ( ! $permission ) {
|
||||
if ( ! $permission || ! $this->is_feature_enabled() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -189,6 +199,7 @@ class CreateAccount extends AbstractOrderConfirmationBlock {
|
|||
protected function enqueue_data( array $attributes = [] ) {
|
||||
parent::enqueue_data( $attributes );
|
||||
|
||||
$this->asset_data_registry->add( 'delayedAccountCreationEnabled', $this->is_feature_enabled() );
|
||||
$this->asset_data_registry->add( 'registrationGeneratePassword', filter_var( get_option( 'woocommerce_registration_generate_password' ), FILTER_VALIDATE_BOOLEAN ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue