Skip to content

Instantly share code, notes, and snippets.

@alexclst
Created February 10, 2023 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexclst/30db696d68d7d54d7279b41f6de30535 to your computer and use it in GitHub Desktop.
Save alexclst/30db696d68d7d54d7279b41f6de30535 to your computer and use it in GitHub Desktop.
Force Stripe Test Mode in WooCommerce
<?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