Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
<?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;
}
?>
<?php
if( woocommerce_version_check() ) {
// Use new, updated functions
} else {
// Use older, deprecated functions
}
?>
@pablo-sg-pacheco

This comment has been minimized.

Copy link

@pablo-sg-pacheco pablo-sg-pacheco commented Apr 19, 2017

I think this function is_woocommerce_active() no longer exists. So i prefer to check if class exists, like this:

public static function version_check( $version = '3.0' ) {
	if ( class_exists( 'WooCommerce' ) ) {
		global $woocommerce;
		if ( version_compare( $woocommerce->version, $version, ">=" ) ) {
			return true;
		}
	}
	return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.