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 (
2023-12-19 10:13:45 +00:00
'wcgateway.button.locations' => function ( array $locations , ContainerInterface $container ) : array {
2023-03-29 20:15:42 +03:00
return array_merge (
$locations ,
array (
2024-01-08 08:17:48 +02:00
'checkout-block-express' => _x ( 'Express Checkout' , 'Name of Buttons Location' , 'woocommerce-paypal-payments' ),
'cart-block' => _x ( 'Cart' , 'Name of Buttons Location' , 'woocommerce-paypal-payments' ),
2023-03-29 20:15:42 +03:00
)
);
},
2023-12-19 10:13:45 +00:00
'wcgateway.settings.pay-later.messaging-locations' => function ( array $locations , ContainerInterface $container ) : array {
2023-03-29 20:15:42 +03:00
unset ( $locations [ 'checkout-block-express' ] );
unset ( $locations [ 'cart-block' ] );
return $locations ;
},
2023-04-18 16:55:01 +03:00
2023-12-19 10:13:45 +00:00
'wcgateway.settings.fields' => function ( array $fields , ContainerInterface $container ) : array {
2023-04-18 16:55:01 +03:00
$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 ) );
};
2024-05-06 19:35:17 +04:00
$label = __ (
' Enable this option to require customers to manually confirm express payments on the checkout page .
< p class = " description " > This ensures they can review the order , update shipping options , and fill in eventual custom fields necessary for the transaction .</ p >
< p class = " description " > If this is disabled , the system will automatically synchronize shipping options with PayPal and bypass the final checkout confirmation . This expedites the checkout process but prevents buyers from filling in eventual custom fields and reviewing final details before finalizing the payment .</ p > ' ,
'woocommerce-paypal-payments'
);
2024-11-06 09:45:03 +01:00
/**
* Replace wc_terms_and_conditions_page_id () function to avoid errors when to avoid errors because of early loading .
*/
$wc_terms_and_conditions_page_id = apply_filters ( 'woocommerce_get_terms_page_id' , get_option ( 'woocommerce_terms_page_id' ) );
$wc_terms_and_conditions_page_id = apply_filters ( 'woocommerce_terms_and_conditions_page_id' , 0 < $wc_terms_and_conditions_page_id ? absint ( $wc_terms_and_conditions_page_id ) : 0 );
if ( $wc_terms_and_conditions_page_id > 0 ) {
2024-05-06 19:35:17 +04:00
$label .= __ (
2024-05-16 17:23:00 +04:00
'<div class="ppcp-notice ppcp-notice-warning"><p><span class="highlight">Important:</span> Your store has a <a href="/wp-admin/admin.php?page=wc-settings&tab=advanced" target="_blank">Terms and Conditions</a> page configured. Buyers who use a PayPal express payment method will not be able to consent to the terms on the <code>Classic Checkout</code>, as the final checkout confirmation will be skipped.</p></div>' ,
2024-05-06 19:35:17 +04:00
'woocommerce-paypal-payments'
);
}
2024-05-20 15:29:56 +04:00
$should_disable_checkbox = apply_filters ( 'woocommerce_paypal_payments_toggle_final_review_checkbox' , false );
2024-05-17 18:12:14 +04:00
2023-04-18 16:55:01 +03:00
return $insert_after (
$fields ,
2023-05-08 15:04:25 +03:00
'smart_button_locations' ,
2023-04-18 16:55:01 +03:00
array (
2023-04-24 08:12:48 +03:00
'blocks_final_review_enabled' => array (
2023-05-08 15:04:25 +03:00
'title' => __ ( 'Require final confirmation on checkout' , 'woocommerce-paypal-payments' ),
2023-04-18 16:55:01 +03:00
'type' => 'checkbox' ,
2024-05-06 19:35:17 +04:00
'label' => $label ,
2024-08-21 18:23:22 +02:00
'default' => true ,
2023-04-18 16:55:01 +03:00
'screens' => array ( State :: STATE_START , State :: STATE_ONBOARDED ),
'requirements' => array (),
'gateway' => 'paypal' ,
2024-05-17 15:47:52 +04:00
'class' => array ( 'ppcp-grayed-out-text' ),
2024-05-17 18:12:14 +04:00
'input_class' => $should_disable_checkbox ? array ( 'ppcp-disabled-checkbox' ) : array (),
2023-04-18 16:55:01 +03:00
),
)
);
},
2023-04-24 08:15:22 +03:00
2023-12-19 10:13:45 +00:00
'button.pay-now-contexts' => function ( array $contexts , ContainerInterface $container ) : array {
2023-04-24 08:15:22 +03:00
if ( ! $container -> get ( 'blocks.settings.final_review_enabled' ) ) {
2023-04-27 12:49:26 +03:00
$contexts [] = 'checkout-block' ;
2023-04-24 08:15:22 +03:00
$contexts [] = 'cart-block' ;
}
return $contexts ;
},
2023-04-25 15:06:24 +03:00
2023-12-19 10:13:45 +00:00
'button.handle-shipping-in-paypal' => function ( bool $previous , ContainerInterface $container ) : bool {
2023-04-25 15:06:24 +03:00
return ! $container -> get ( 'blocks.settings.final_review_enabled' );
},
2023-03-29 20:15:42 +03:00
);