根据主机名强制 Stripe WooCommerce 插件进入测试模式

Force Stripe WooCommerce Addon into testmode depending on hostname

我正在寻找一种方法来强制 Stripe Woocommerce 插件进入测试模式,如果网站是在本地或临时网站上设置的。我还没有找到任何可以为我指明正确方向的资源。

我在 class-wc-gateway-strip.php 中找到了获取设置值的代码:

// Get setting values.
    $this->title                  = $this->get_option( 'title' );
    $this->description            = $this->get_option( 'description' );
    $this->enabled                = $this->get_option( 'enabled' );
    $this->testmode               = 'yes' === $this->get_option( 'testmode' );
    $this->capture                = 'yes' === $this->get_option( 'capture', 'yes' );
    $this->stripe_checkout        = 'yes' === $this->get_option( 'stripe_checkout' );
    $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' );
    $this->stripe_checkout_image  = $this->get_option( 'stripe_checkout_image', '' );
    $this->saved_cards            = 'yes' === $this->get_option( 'saved_cards' );
    $this->secret_key             = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
    $this->publishable_key        = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
    $this->bitcoin                = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' );
    $this->logging                = 'yes' === $this->get_option( 'logging' );

我已经尝试对域进行检查并尝试 update_option('testmode','yes'); 但这似乎没有任何效果。

有什么想法或资源可以帮助我前进吗?

未经测试,但根据我的评论,我认为您可以调整选项。

add_action( 'init', 'so_40555974_stripe_testing' );
function so_40555974_stripe_testing(){

    $localIPs = array(
        '127.0.0.1',
        '::1'
    );

    // or use your own conditional logic for determining local/testing server
    if( in_array($_SERVER['REMOTE_ADDR'], $localIPs ) ){
        $settings = get_option("woocommerce_stripe_settings");
        $settings["testmode"] = "yes";
        update_option("woocommerce_stripe_settings", $settings );
    }
}