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: https://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
} 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x