Skip to content

Commit

Permalink
Make subs active/ver functions filterable
Browse files Browse the repository at this point in the history
  • Loading branch information
unfulvio committed Sep 26, 2024
1 parent 86e3200 commit 7b2c62c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
17 changes: 13 additions & 4 deletions woocommerce/class-sv-wc-plugin-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,31 @@ public static function is_wc_subscriptions_version_lt( $version ) {
*/
protected static function get_wc_subscriptions_version() : ?string {

$version = null;

if ( class_exists( 'WC_Subscriptions' ) && ! empty( \WC_Subscriptions::$version ) ) {
return \WC_Subscriptions::$version;
$version = \WC_Subscriptions::$version;
}

if ( class_exists( 'WC_Subscriptions_Core_Plugin' ) ) {
if ( ! $version && class_exists( 'WC_Subscriptions_Core_Plugin' ) ) {
if ( is_callable( [ \WC_Subscriptions_Core_Plugin::class, 'instance' ] ) ) {

$instance = \WC_Subscriptions_Core_Plugin::instance();

if ( is_object( $instance ) && method_exists( $instance, 'get_library_version' ) ) {
return $instance->get_library_version();
$version = $instance->get_library_version();
}
}
}

return null;
/**
* Filters the WooCommerce Subscriptions version when fetched by the framework.
*
* This accounts for cases where the version is not found by the framework as Subscriptions may be embedded as a core library by third party code.
*
* @param string $version WooCommerce Subscriptions version
*/
return (string) apply_filters( 'sv_wc_plugin_framework_wc_subscriptions_version', $version );
}


Expand Down
13 changes: 11 additions & 2 deletions woocommerce/payment-gateway/class-sv-wc-payment-gateway-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ public function get_accepted_currencies() {


/**
* Checks is WooCommerce Subscriptions is active
* Checks is WooCommerce Subscriptions is active as a plugin or as a core library
*
* @since 1.0.0
*
Expand All @@ -1370,7 +1370,16 @@ public function is_subscriptions_active() : bool {
return $this->subscriptions_active;
}

return $this->subscriptions_active = class_exists( 'WC_Subscriptions_Core_Plugin' ) || $this->is_plugin_active( 'woocommerce-subscriptions.php' );
$this->subscriptions_active = class_exists( 'WC_Subscriptions_Core_Plugin' ) || $this->is_plugin_active( 'woocommerce-subscriptions.php' );

/**
* Filters whether WooCommerce Subscriptions is active.
*
* This future proofs the plugin for when WooCommerce Subscriptions is included as a core library or third party plugin embedding the core library.
*
* @param bool $subscriptions_active
*/
return apply_filters( 'sv_wc_payment_gateway_is_subscriptions_active', $this->subscriptions_active );
}


Expand Down

0 comments on commit 7b2c62c

Please sign in to comment.