Skip to content

Commit

Permalink
Add support for WooCommerce Subscriptions (#85)
Browse files Browse the repository at this point in the history
Handle rewrite of URLs via custom filter for subscriptions when on staging.

ref: https://secure.helpscout.net/conversation/1491883253/20466?folderId=3696111
  • Loading branch information
dz0ny authored Apr 23, 2021
1 parent 6bf85fc commit 7e6e52e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 3.30.0
VERSION := 3.30.1
PLUGINSLUG := woocart-defaults
SRCPATH := $(shell pwd)/src

Expand Down
11 changes: 11 additions & 0 deletions src/classes/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class WooCommerce {

public function __construct() {
add_filter( 'woocommerce_general_settings', array( &$this, 'general_settings' ) );
add_filter( 'woocommerce_subscriptions_is_duplicate_site', array( &$this, 'woocommerce_subscriptions_is_duplicate' ) );
}

/**
Expand Down Expand Up @@ -44,6 +45,16 @@ public function general_settings( $settings ) {
return $updated_settings;
}

/**
* Return true if we are on anything but production site.
*
* @return bool
*/
public function woocommerce_subscriptions_is_duplicate() {

return wp_get_environment_type() !== 'production';
}

}

}
37 changes: 37 additions & 0 deletions tests/WooCommerceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function tearDown() : void {
public function testConstructor() {
$woocommerce = new WooCommerce();
\WP_Mock::expectFilterAdded( 'woocommerce_general_settings', array( $woocommerce, 'general_settings' ) );
\WP_Mock::expectFilterAdded( 'woocommerce_subscriptions_is_duplicate_site', array( $woocommerce, 'woocommerce_subscriptions_is_duplicate' ) );
$woocommerce->__construct();
\WP_Mock::assertHooksAdded();
}
Expand Down Expand Up @@ -63,4 +64,40 @@ public function testGeneralSettings() {
);
}

/**
* @covers ::__construct
* @covers ::woocommerce_subscriptions_is_duplicate
*/
public function test_is_duplicate_site_local() {
$woocommerce = new WooCommerce();
\WP_Mock::userFunction(
'wp_get_environment_type',
array(
'return' => 'local',
)
);
$this->assertTrue(
$woocommerce->woocommerce_subscriptions_is_duplicate()
);

}

/**
* @covers ::__construct
* @covers ::woocommerce_subscriptions_is_duplicate
*/
public function test_is_duplicate_site_production() {
$woocommerce = new WooCommerce();
\WP_Mock::userFunction(
'wp_get_environment_type',
array(
'return' => 'production',
)
);
$this->assertFalse(
$woocommerce->woocommerce_subscriptions_is_duplicate()
);

}

}

0 comments on commit 7e6e52e

Please sign in to comment.