根据主机名强制Stripe WooCommerce Addon进入testmode

时间:2016-11-11 20:48:16

标签: wordpress woocommerce stripe-payments

如果网站是在本地设置或在暂存网站上设置的,我正在寻找一种方法强制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');,但这似乎没有任何效果。

任何可以帮助我前进的想法或资源?

1 个答案:

答案 0 :(得分:0)

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

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 );
    }
}