woocommerce-paypal-payments/modules/ppcp-blocks/extensions.php

75 lines
2.6 KiB
PHP
Raw Normal View History

2022-12-20 16:04:11 +02:00
<?php
/**
* The blocks module extensions.
*
* @package WooCommerce\PayPalCommerce\Blocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Blocks;
2023-04-18 16:55:01 +03:00
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array(
'wcgateway.button.locations' => function ( ContainerInterface $container, array $locations ): array {
return array_merge(
$locations,
array(
'checkout-block-express' => _x( 'Block Express Checkout', 'Name of Buttons Location', 'woocommerce-paypal-payments' ),
'cart-block' => _x( 'Block Cart', 'Name of Buttons Location', 'woocommerce-paypal-payments' ),
)
);
},
'wcgateway.settings.pay-later.messaging-locations' => function ( ContainerInterface $container, array $locations ): array {
unset( $locations['checkout-block-express'] );
unset( $locations['cart-block'] );
return $locations;
},
2023-04-18 16:55:01 +03:00
'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array {
$insert_after = function( array $array, string $key, array $new ): array {
$keys = array_keys( $array );
$index = array_search( $key, $keys, true );
$pos = false === $index ? count( $array ) : $index + 1;
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
};
return $insert_after(
$fields,
'smart_button_enable_styling_per_location',
array(
2023-04-24 08:12:48 +03:00
'blocks_final_review_enabled' => array(
2023-04-18 16:55:01 +03:00
'title' => __( 'Block Express payments Final Review', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __(
'Require customers to confirm Block Express payments on the Checkout page.
If disabled, the Checkout page is skipped for Block Express payments.
<p class="description">This can cause issues and poor UX if the server is not handling the requests fast enough.</p>',
'woocommerce-paypal-payments'
),
2023-04-18 16:55:01 +03:00
'default' => true,
'screens' => array( State::STATE_START, State::STATE_ONBOARDED ),
'requirements' => array(),
'gateway' => 'paypal',
),
)
);
},
'button.pay-now-contexts' => function ( ContainerInterface $container, array $contexts ): array {
if ( ! $container->get( 'blocks.settings.final_review_enabled' ) ) {
2023-04-27 12:49:26 +03:00
$contexts[] = 'checkout-block';
$contexts[] = 'cart-block';
}
return $contexts;
},
'button.handle-shipping-in-paypal' => function ( ContainerInterface $container ): bool {
return ! $container->get( 'blocks.settings.final_review_enabled' );
},
);