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 ;
2023-03-29 20:15:42 +03:00
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.' , 'woocommerce-paypal-payments' ),
'default' => true ,
'screens' => array ( State :: STATE_START , State :: STATE_ONBOARDED ),
'requirements' => array (),
'gateway' => 'paypal' ,
),
)
);
},
2023-04-24 08:15:22 +03:00
'button.pay-now-contexts' => function ( ContainerInterface $container , array $contexts ) : array {
$contexts [] = 'checkout-block' ;
if ( ! $container -> get ( 'blocks.settings.final_review_enabled' ) ) {
$contexts [] = 'cart-block' ;
}
return $contexts ;
},
2023-03-29 20:15:42 +03:00
);