Skip to content

Instantly share code, notes, and snippets.

@hansschuijff
Last active November 11, 2020 13:54
Show Gist options
  • Save hansschuijff/4cc58d1ef85962f5f4b589c8eb76a349 to your computer and use it in GitHub Desktop.
Save hansschuijff/4cc58d1ef85962f5f4b589c8eb76a349 to your computer and use it in GitHub Desktop.
Force the display_logo setting of all Mollie Payment methods to "no"
<?php
/**
* Forces the display_logo setting to "no"
* on all Mollie gateways
*
* @package DeWittePrins\CoreFunctionality;
* @since 1.7.12
* @author Hans Schuijff
* @link https://dewitteprins.nl
* @license GNU-2.0+
*/
namespace DeWittePrins\CoreFunctionality\Mollie;
/**
* Adds a filter for every mollie payment method option
*
* @since 1.7.12
*
* @return void
*/
function add_mollie_gateway_options_filter() {
$mollie_gateway_options = get_mollie_gateway_options();
foreach ($mollie_gateway_options as $option) {
add_filter( "option_{$option}", __NAMESPACE__ . '\filter_mollie_gateway_options' );
}
}
add_action( 'init', __NAMESPACE__ . '\add_mollie_gateway_options_filter');
/**
* Sets "display_logo" to 'no' for Mollie gateways
*
* no need to test the option key, since this function
* is used as a callback that should only be called
* for relevant options
*
* @since 1.7.12
*
* @param array $value Value of the option.
* @return array Same as $value, but with display_logo set to "no"
*/
function filter_mollie_gateway_options( $value ) {
if ( is_array( $value)
&& isset( $value['display_logo'] ) ) {
$value['display_logo'] = 'no';
}
return $value;
}
/**
* Returns an array with option-keys for all mollie gateways
*
* @since 1.7.12
*
* @return array
*/
function get_mollie_gateway_options() {
return [
"mollie_wc_gateway_banktransfer_settings",
"mollie_wc_gateway_belfius_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_creditcard_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_eps_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_giropay_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_ideal_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_inghomepay_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_kbc_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_klarnapaylater_settings",
"mollie_wc_gateway_klarnasliceit_settings",
"mollie_wc_gateway_bancontact_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_mistercash_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_paypal_settings",
"mollie_wc_gateway_paysafecard_settings",
"mollie_wc_gateway_przelewy24_settings",
"mollie_wc_gateway_sofort_settings",
"mollie_wc_gateway_directdebit_settings",
"mollie_wc_gateway_giftcard_settings",
"mollie_wc_gateway_applepay_settings",
"mollie_wc_gateway_mybank_settings",
"mollie_wc_gateway_mealvoucher_settings",
];
}
/**
* Returns an array with option-keys for all native woocommerce gateways
*
* @since 1.7.12
*
* @return array
*/
function get_woocommerce_gateway_options() {
return [
"woocommerce_bacs_settings",
"woocommerce_cheque_settings",
"woocommerce_cod_settings",
"woocommerce_paypal_settings",
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment