♻️ Improve SDK component inject logic

Just make the filter callback more readable, still no change in the plugin logic
This commit is contained in:
Philipp Stracker 2025-03-12 17:33:44 +01:00
parent 791a5d33da
commit de46e4ed08
No known key found for this signature in database

View file

@ -53,19 +53,22 @@ class CardFieldsModule implements ServiceModule, ExtendingModule, ExecutableModu
*/
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
function( $components ) use ( $c ) {
if ( ! $c->get( 'wcgateway.configuration.dcc' )->is_enabled() ) {
static function( $components ) use ( $c ) {
$dcc_config = $c->get( 'wcgateway.configuration.dcc' );
assert( $dcc_config instanceof DCCGatewayConfiguration );
if ( ! $dcc_config->is_enabled() ) {
return $components;
}
if ( in_array( 'hosted-fields', $components, true ) ) {
$key = array_search( 'hosted-fields', $components, true );
if ( $key !== false ) {
unset( $components[ $key ] );
}
}
// Enable the new "card-fields" component.
$components[] = 'card-fields';
return $components;
// Ensure the older "hosted-fields" component is not loaded.
return array_filter(
$components,
static fn( string $component ) => $component !== 'hosted-fields'
);
}
);