Created
February 10, 2023 17:01
-
-
Save alexclst/30db696d68d7d54d7279b41f6de30535 to your computer and use it in GitHub Desktop.
Force Stripe Test Mode in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Force Stripe Test Mode | |
* Plugin URI: https://tenseg.net | |
* Description: Forces Stripe into test mode if TG_STRIPE_TEST_MODE defined as 'yes'. | |
* Author: Tenseg LLC | |
* Author URI: https://tenseg.net | |
* Text Domain: force-stripe-test-mode | |
* Version: 1.0.0 | |
* | |
* @package force-stripe-test-mode | |
*/ | |
// based on https://stackoverflow.com/a/40564861/822151 | |
add_action( 'init', 'tg_check_if_stripe_should_be_testing' ); | |
function tg_check_if_stripe_should_be_testing() { | |
if ( defined( 'TG_STRIPE_TEST_MODE' ) && constant( 'TG_STRIPE_TEST_MODE' ) == 'yes' ) { | |
$settings = get_option( 'woocommerce_stripe_settings' ); | |
if ( rgar( $settings, 'testmode' ) != 'yes' ) { | |
$settings['testmode'] = 'yes'; | |
update_option( 'woocommerce_stripe_settings', $settings ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment