Last active
December 13, 2023 12:19
-
-
Save hlashbrooke/9133402 to your computer and use it in GitHub Desktop.
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function woocommerce_version_check( $version = '2.1' ) { | |
if ( function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) { | |
global $woocommerce; | |
if( version_compare( $woocommerce->version, $version, ">=" ) ) { | |
return true; | |
} | |
} | |
return false; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( woocommerce_version_check() ) { | |
// Use new, updated functions | |
} else { | |
// Use older, deprecated functions | |
} | |
?> |
<?php echo WC()->version; ?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this function is_woocommerce_active() no longer exists. So i prefer to check if class exists, like this: