♻️ Move DCC hooks to separate helper method

This commit is contained in:
Philipp Stracker 2025-03-17 15:23:29 +01:00
parent 3cfbd1002f
commit 3fead84a70
No known key found for this signature in database

View file

@ -342,6 +342,51 @@ class SmartButton implements SmartButtonInterface {
}
if ( $this->dcc_configuration->is_enabled() ) {
$this->render_dcc_wrapper();
}
if ( $this->is_free_trial_cart() ) {
add_action(
'woocommerce_review_order_after_submit',
function () {
$vaulted_email = $this->get_vaulted_paypal_email();
if ( ! $vaulted_email ) {
return;
}
?>
<div class="ppcp-vaulted-paypal-details">
<?php
echo wp_kses_post(
sprintf(
// translators: %1$s - email, %2$s, %3$s - HTML tags for a link.
esc_html__(
'Using %2$s%1$s%3$s PayPal.',
'woocommerce-paypal-payments'
),
$vaulted_email,
'<b>',
'</b>'
)
);
?>
</div>
<?php
}
);
}
$this->sanitize_woocommerce_filters();
return true;
}
/**
* Registers hooks and callbacks that are only relevant for DCC (ACDC) payments.
*
* @return void
*/
private function render_dcc_wrapper(): void {
add_action(
$this->checkout_dcc_button_renderer_hook(),
array( $this, 'dcc_renderer' ),
@ -359,10 +404,10 @@ class SmartButton implements SmartButtonInterface {
'woocommerce_credit_card_form_fields',
function ( array $default_fields, $id ) use ( $subscription_helper ) : array {
if (
is_user_logged_in()
CreditCardGateway::ID === $id
&& is_user_logged_in()
&& $this->settings->has( 'vault_enabled_dcc' )
&& $this->settings->get( 'vault_enabled_dcc' )
&& CreditCardGateway::ID === $id
&& apply_filters( 'woocommerce_paypal_payments_should_render_card_custom_fields', true )
) {
@ -404,42 +449,6 @@ class SmartButton implements SmartButtonInterface {
);
}
if ( $this->is_free_trial_cart() ) {
add_action(
'woocommerce_review_order_after_submit',
function () {
$vaulted_email = $this->get_vaulted_paypal_email();
if ( ! $vaulted_email ) {
return;
}
?>
<div class="ppcp-vaulted-paypal-details">
<?php
echo wp_kses_post(
sprintf(
// translators: %1$s - email, %2$s, %3$s - HTML tags for a link.
esc_html__(
'Using %2$s%1$s%3$s PayPal.',
'woocommerce-paypal-payments'
),
$vaulted_email,
'<b>',
'</b>'
)
);
?>
</div>
<?php
}
);
}
$this->sanitize_woocommerce_filters();
return true;
}
/**
* Registers the hooks to render the credit messaging HTML depending on the settings.
*