Skip to content

Instantly share code, notes, and snippets.

@growdev
Last active December 11, 2015 12:38
Show Gist options
  • Save growdev/4601948 to your computer and use it in GitHub Desktop.
Save growdev/4601948 to your computer and use it in GitHub Desktop.
Detecting version of WooCommerce for Payment Gateways to make them compatible with WC 2.0
<?php
/*
* Use this in __construct() to set appropriate options update
*/
if ( preg_match('/1\.[0-9]*\.[0-9]*/', WOOCOMMERCE_VERSION )){
// 1.*.*
add_action('woocommerce_update_options_payment_gateways', array( $this, 'process_admin_options'));
} else {
// 2.*.*
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options'));
}
/*
* Use this in the process_payment() method to clear the awaiting payment flag
*/
// Empty awaiting payment session
if ( preg_match('/1\.[0-9]*\.[0-9]*/', WOOCOMMERCE_VERSION )){
unset($_SESSION['order_awaiting_payment']);
} else {
unset( $woocommerce->session->order_awaiting_payment );
}
@maxrice
Copy link

maxrice commented Jan 23, 2013

@growdev could use version_compare instead of preg_match -- it's designed for this sort of thing 😄

@growdev
Copy link
Author

growdev commented Jan 25, 2013

Know that now. I like getting my regex on!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment