From 995cd438399f3324134674e7a72154d0278b50b8 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 11 May 2022 10:11:13 +0200 Subject: [PATCH] Do not enable pui gateway if customer service instructions is empty --- .../Gateway/PayUponInvoice/PayUponInvoice.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php index d10c5b92e..a5daacfd9 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoice.php @@ -342,6 +342,43 @@ class PayUponInvoice { } } ); + + add_action( + 'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway', + function () { + $customer_service_instructions = filter_input( INPUT_POST, 'woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions', FILTER_SANITIZE_STRING ); + if ( '' === $customer_service_instructions ) { + $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); + $gateway_enabled = $gateway_settings['enabled'] ?? ''; + if ( 'yes' === $gateway_enabled ) { + $gateway_settings['enabled'] = 'no'; + update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings ); + + $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' ); + wp_safe_redirect( $redirect_url ); + exit; + } + } + } + ); + + add_action( + 'woocommerce_settings_checkout', + function() { + if ( + PayUponInvoiceGateway::ID === $this->current_ppcp_settings_page_id + && $this->pui_product_status->pui_is_active() + ) { + $pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ]; + if ( $pui_gateway->get_option( 'customer_service_instructions' ) === '' ) { + printf( + '

%1$s

', + esc_html__( 'Could not enable gateway because "Customer service instructions" field is empty.', 'woocommerce-paypal-payments' ) + ); + } + } + } + ); } /**