|
/**************************************************************************************** |
|
* START - Disable a payment gateway and show a custom message in WooCommerce |
|
****************************************************************************************/ |
|
|
|
/** |
|
* Define constants at the top for easy configuration. |
|
*/ |
|
define('DISABLE_GATEWAY_ID', 'plisio'); |
|
define('DISABLE_MESSAGE', '<div class="woocommerce-error">Cryptocurrency payments are temporarily unavailable while we improve the payment process.</div>'); |
|
|
|
add_filter('woocommerce_available_payment_gateways', 'disable_payment_gateway', 10, 1); |
|
|
|
function disable_payment_gateway($available_gateways) { |
|
if (isset($available_gateways[DISABLE_GATEWAY_ID])) { |
|
// Disable the payment method but still display it |
|
$available_gateways[DISABLE_GATEWAY_ID]->enabled = false; |
|
|
|
// Add custom message to the description |
|
$available_gateways[DISABLE_GATEWAY_ID]->description = DISABLE_MESSAGE . $available_gateways[DISABLE_GATEWAY_ID]->description; |
|
} |
|
return $available_gateways; |
|
} |
|
|
|
add_action('wp_footer', 'disable_checkout_button_for_payment_method'); |
|
|
|
function disable_checkout_button_for_payment_method() { |
|
if (is_checkout()) { |
|
?> |
|
<script type="text/javascript"> |
|
jQuery(document).ready(function($) { |
|
// Continuously check for changes in payment method selection |
|
$('form.checkout').on('change', 'input[name="payment_method"]', function() { |
|
// Check if the disabled payment method is selected |
|
if ($('input[name="payment_method"]:checked').val() === '<?php echo DISABLE_GATEWAY_ID; ?>') { |
|
// Disable the place order button |
|
$('#place_order').prop('disabled', true).css('opacity', '0.5'); |
|
} else { |
|
// Enable the place order button if other methods are selected |
|
$('#place_order').prop('disabled', false).css('opacity', '1'); |
|
} |
|
}); |
|
|
|
// Trigger the change event on page load in case the method is already selected |
|
$('input[name="payment_method"]:checked').trigger('change'); |
|
}); |
|
</script> |
|
<?php |
|
} |
|
} |
|
|
|
/**************************************************************************************** |
|
* END - Disable a payment gateway and show a custom message in WooCommerce |
|
****************************************************************************************/ |