Skip to content

Commit

Permalink
Removed support for WooCommerce 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jun 21, 2015
1 parent d798d83 commit 53d4f95
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
18 changes: 1 addition & 17 deletions includes/admin/class-wc-payment-discounts-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public function __construct() {
// Register plugin settings.
add_action( 'admin_init', array( $this, 'register_settings' ) );

// Need update message.
if ( defined( 'WOOCOMMERCE_VERSION' ) && ! version_compare( WOOCOMMERCE_VERSION, '2.0', '>=' ) ) {
add_action( 'admin_notices', array( $this, 'woocommerce_need_update' ) );
}

$this->maybe_update();
}

Expand Down Expand Up @@ -93,22 +88,11 @@ public function validate_settings( $options ) {
* @return string Settings page content.
*/
public function display_plugin_admin_page() {
global $woocommerce;

$settings = get_option( 'woocommerce_payment_discounts' );
$payment_gateways = $woocommerce->payment_gateways->payment_gateways();
$payment_gateways = WC()->payment_gateways->payment_gateways();

include_once 'views/html-admin-settings.php';
}

/**
* WooCommerce need update.
*
* @return string Admin notice.
*/
public function woocommerce_need_update() {
echo '<div class="error"><p>' . __( '<strong>WooCommerce Discounts Per Payment Method</strong> works only with WooCommerce 2.0 or higher, please, upgrade you WooCommerce!', 'woocommerce-payment-discounts' ) . '</p></div>';
}
}

new WC_Payment_Discounts_Admin();
12 changes: 5 additions & 7 deletions includes/class-wc-payment-discounts-add-discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function payment_method_title( $title, $id ) {
if ( strstr( $discount, '%' ) ) {
$value = $discount;
} else {
$value = woocommerce_price( $discount );
$value = wc_price( $discount );
}

$title .= ' <small>(' . sprintf( __( '%s off', 'woocommerce-payment-discounts' ), $value ) . ')</small>';
Expand All @@ -106,20 +106,18 @@ public function add_discount( $cart ) {
return;
}

global $woocommerce;

// Gets the settings.
$gateways = get_option( 'woocommerce_payment_discounts' );

if ( isset( $gateways[ $woocommerce->session->chosen_payment_method ] ) ) {
if ( isset( $gateways[ WC()->session->chosen_payment_method ] ) ) {
// Gets the gateway discount.
$value = $gateways[ $woocommerce->session->chosen_payment_method ];
$value = $gateways[ WC()->session->chosen_payment_method ];

if ( apply_filters( 'wc_payment_discounts_apply_discount', 0 < $value, $cart ) ) {

// Gets the gateway data.
$payment_gateways = $woocommerce->payment_gateways->payment_gateways();
$gateway = $payment_gateways[ $woocommerce->session->chosen_payment_method ];
$payment_gateways = WC()->payment_gateways->payment_gateways();
$gateway = $payment_gateways[ WC()->session->chosen_payment_method ];

// Generate the discount amount and title.
$discount_name = $this->discount_name( $value, $gateway );
Expand Down
4 changes: 0 additions & 4 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
exit;
}

// Delete old options.
delete_option( 'wcpaydisc_settings' );
delete_option( 'wcpaydisc_gateways' );

// Delete plugin options.
delete_option( 'woocommerce_payment_discounts' );
delete_option( 'woocommerce_payment_discounts_version' );
4 changes: 2 additions & 2 deletions woocommerce-payment-discounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function __construct() {
// Load plugin text domain.
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );

if ( function_exists( 'WC' ) ) {
if ( defined( 'WC_VERSION' ) && ! version_compare( WC_VERSION, '2.1', '>=' ) ) {
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
$this->admin_includes();
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function load_plugin_textdomain() {
* @return string Admin notice.
*/
public function woocommerce_is_missing_notice() {
echo '<div class="error"><p>' . sprintf( __( '<strong>WooCommerce Discounts Per Payment Method</strong> depends on the last version of %s to work!', 'woocommerce-payment-discounts' ), '<a href="http://wordpress.org/extend/plugins/woocommerce/">' . __( 'WooCommerce', 'woocommerce-payment-discounts' ) . '</a>' ) . '</p></div>';
echo '<div class="error"><p><strong>' . __( 'WooCommerce Discounts Per Payment Method', 'woocommerce-payment-discounts' ) . '</strong> ' . sprintf( __( 'works only with %s 2.1 or higher, please install or upgrade your installation!', 'woocommerce-payment-discounts' ), '<a href="http://wordpress.org/plugins/woocommerce/">' . __( 'WooCommerce', 'woocommerce-payment-discounts' ) . '</a>' ) . '</p></div>';
}
}

Expand Down

0 comments on commit 53d4f95

Please sign in to comment.