Add filter for credit card gateway enabled

This commit is contained in:
Emili Castells Guasch 2025-02-06 14:25:35 +01:00
parent daf5af2870
commit 2d3706291b
2 changed files with 39 additions and 7 deletions

View file

@ -394,6 +394,23 @@ class SettingsModule implements ServiceModule, ExecutableModule {
2
);
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_form_fields',
function( array $form_fields ) {
$form_fields['enabled'] = array(
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
'description' => __( 'Once enabled, the Credit Card option will show up in the checkout.', 'woocommerce-paypal-payments' ),
'label' => __( 'Enable Advanced Card Processing', 'woocommerce-paypal-payments' ),
'default' => 'no',
);
return $form_fields;
}
);
add_filter( 'woocommerce_paypal_payments_credit_card_gateway_should_update_enabled', '__return_false' );
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_title',
function( string $title, WC_Payment_Gateway $gateway ) {

View file

@ -299,10 +299,13 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
* Initialize the form fields.
*/
public function init_form_fields() {
$this->form_fields = array(
$this->form_fields = apply_filters(
'woocommerce_paypal_payments_credit_card_gateway_form_fields',
array(
'ppcp' => array(
'type' => 'ppcp',
),
)
);
}
@ -583,6 +586,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
public function init_settings() {
parent::init_settings();
if ( ! apply_filters( 'woocommerce_paypal_payments_credit_card_gateway_should_update_enabled', true ) ) {
return;
}
// looks like in some cases WC uses this field instead of get_option.
$this->enabled = $this->is_enabled() ? 'yes' : '';
}
@ -595,6 +602,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
* @return mixed
*/
public function get_option( $key, $empty_value = null ) {
if ( ! apply_filters( 'woocommerce_paypal_payments_credit_card_gateway_should_update_enabled', true ) ) {
return parent::get_option( $key, $empty_value );
}
if ( 'enabled' === $key ) {
return $this->is_enabled();
}
@ -612,6 +623,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
public function update_option( $key, $value = '' ) {
$ret = parent::update_option( $key, $value );
if ( ! apply_filters( 'woocommerce_paypal_payments_credit_card_gateway_should_update_enabled', true ) ) {
return $ret;
}
if ( 'enabled' === $key ) {
$this->config->set( 'dcc_enabled', 'yes' === $value );