WordPress Snippets at WPcustoms

Check for the latest WooCommerce version

Check your client’s WooCommerce version to use the latest hooks and filters. Use an optional callback function with this conditional check.


/**
 * Snippet Name: Check for the latest WooCommerce version
 * Snippet URL: http://www.wpcustoms.net/snippets/check-latest-woocommerce-version/
 */
 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;
}

// usage:
if( woocommerce_version_check() ) {
    // Use new, updated functions
} else {
    // Use older, deprecated functions
}