mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
New Settings UI: Conditionally show subscriptions product option
This commit is contained in:
parent
ebc53b7bfa
commit
137d40489c
6 changed files with 41 additions and 25 deletions
|
@ -9,6 +9,7 @@ const PRODUCTS_CHECKBOX_GROUP_NAME = 'products';
|
|||
|
||||
const StepProducts = () => {
|
||||
const { products, setProducts } = OnboardingHooks.useProducts();
|
||||
const { canUseSubscriptions } = OnboardingHooks.useFlags();
|
||||
|
||||
return (
|
||||
<div className="ppcp-r-page-products">
|
||||
|
@ -86,31 +87,33 @@ const StepProducts = () => {
|
|||
</li>
|
||||
</ul>
|
||||
</SelectBox>
|
||||
<SelectBox
|
||||
title={ __(
|
||||
'Subscriptions',
|
||||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
description={ __(
|
||||
'Recurring payments for either physical goods or services.',
|
||||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
name={ PRODUCTS_CHECKBOX_GROUP_NAME }
|
||||
value={ PRODUCT_TYPES.SUBSCRIPTIONS }
|
||||
changeCallback={ setProducts }
|
||||
currentValue={ products }
|
||||
type="checkbox"
|
||||
>
|
||||
<a
|
||||
target="__blank"
|
||||
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
|
||||
>
|
||||
{ __(
|
||||
'WooCommerce Subscriptions',
|
||||
{ canUseSubscriptions && (
|
||||
<SelectBox
|
||||
title={ __(
|
||||
'Subscriptions',
|
||||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
</a>
|
||||
</SelectBox>
|
||||
description={ __(
|
||||
'Recurring payments for either physical goods or services.',
|
||||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
name={ PRODUCTS_CHECKBOX_GROUP_NAME }
|
||||
value={ PRODUCT_TYPES.SUBSCRIPTIONS }
|
||||
changeCallback={ setProducts }
|
||||
currentValue={ products }
|
||||
type="checkbox"
|
||||
>
|
||||
<a
|
||||
target="__blank"
|
||||
href="https://woocommerce.com/document/woocommerce-paypal-payments/#subscriptions-faq"
|
||||
>
|
||||
{ __(
|
||||
'WooCommerce Subscriptions',
|
||||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
</a>
|
||||
</SelectBox>
|
||||
) }
|
||||
</SelectBoxWrapper>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -123,3 +123,8 @@ export const useNavigationState = () => {
|
|||
business,
|
||||
};
|
||||
};
|
||||
|
||||
export const useFlags = () => {
|
||||
const { flags } = useHooks();
|
||||
return flags;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ const defaultTransient = {
|
|||
canUseCasualSelling: false,
|
||||
canUseVaulting: false,
|
||||
canUseCardPayments: false,
|
||||
canUseSubscriptions: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ return array(
|
|||
$can_use_casual_selling = $container->get( 'settings.casual-selling.eligible' );
|
||||
$can_use_vaulting = $container->has( 'save-payment-methods.eligible' ) && $container->get( 'save-payment-methods.eligible' );
|
||||
$can_use_card_payments = $container->has( 'card-fields.eligible' ) && $container->get( 'card-fields.eligible' );
|
||||
$can_use_subscriptions = $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' )->plugin_is_active();
|
||||
|
||||
// Card payments are disabled for this plugin when WooPayments is active.
|
||||
// TODO: Move this condition to the card-fields.eligible service?
|
||||
|
@ -47,7 +48,8 @@ return array(
|
|||
return new OnboardingProfile(
|
||||
$can_use_casual_selling,
|
||||
$can_use_vaulting,
|
||||
$can_use_card_payments
|
||||
$can_use_card_payments,
|
||||
$can_use_subscriptions
|
||||
);
|
||||
},
|
||||
'settings.data.general' => static function ( ContainerInterface $container ) : GeneralSettings {
|
||||
|
|
|
@ -48,13 +48,15 @@ class OnboardingProfile extends AbstractDataModel {
|
|||
public function __construct(
|
||||
bool $can_use_casual_selling = false,
|
||||
bool $can_use_vaulting = false,
|
||||
bool $can_use_card_payments = false
|
||||
bool $can_use_card_payments = false,
|
||||
bool $can_use_subscriptions = false
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->flags['can_use_casual_selling'] = $can_use_casual_selling;
|
||||
$this->flags['can_use_vaulting'] = $can_use_vaulting;
|
||||
$this->flags['can_use_card_payments'] = $can_use_card_payments;
|
||||
$this->flags['can_use_subscriptions'] = $can_use_subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,6 +77,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
|
|||
'can_use_card_payments' => array(
|
||||
'js_name' => 'canUseCardPayments',
|
||||
),
|
||||
'can_use_subscriptions' => array(
|
||||
'js_name' => 'canUseSubscriptions',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue