Plugin Directory

Changeset 2924328


Ignore:
Timestamp:
06/10/2023 11:25:21 PM (3 years ago)
Author:
asofantzis
Message:

Do some version checking

Location:
simple-cod-fee-for-woocommerce
Files:
12 added
3 edited

Legend:

Unmodified
Added
Removed
  • simple-cod-fee-for-woocommerce/trunk/includes/admin-menu.php

    r2924277 r2924328  
    1414    echo '<div class="wrap">';
    1515    echo '<h1>Simple Cash on Delivery Fees</h1>';
    16 
     16   
    1717    $gateways = WC()->payment_gateways->get_available_payment_gateways();
    1818
  • simple-cod-fee-for-woocommerce/trunk/readme.txt

    r2924277 r2924328  
    55Tested up to: 6.2
    66Requires PHP: 7.0
    7 Stable tag: 2.0
     7Stable tag: 2.0.1
    88License: GPLv2 or later
    99
     
    3636
    3737== Changelog ==
     38= 2.0.1 =
     39* Fix errors when settings from version 1.7.x never migrated to 2.0 and fatal errors occured
    3840
    3941= 2.0 =
  • simple-cod-fee-for-woocommerce/trunk/simple-cod-fee-for-woocommerce.php

    r2924277 r2924328  
    33Plugin Name: Simple COD Fee for WooCommerce
    44Description: Simply add extra fee for WooCommerce Cash On Delivery payment method
    5 Version: 2.0
     5Version: 2.0.1
    66Author: Andreas Sofantzis
    77Author URI: https://83pixel.com
     
    1515
    1616define('SCFFW_COD_SETTINGS', 'scffw_cod_settings');
     17define('SCFFW_VERSION', '2.0.1');
     18define('SCFFW_VERSION_OPTIONS', 'scffw_version');
    1719
    1820register_activation_hook( __FILE__, function() {
     
    468470    <?php
    469471});
     472
     473add_action('admin_init', function() {
     474    $current_version_installed = get_option(SCFFW_VERSION_OPTIONS);
     475
     476    if ( version_compare( $current_version_installed, SCFFW_VERSION, '<') ) {
     477
     478        $settings = get_option(SCFFW_COD_SETTINGS);
     479   
     480        // if no current settings exists it means that it is a new installation on ver 2.0 and above
     481        if ( !$settings ) {
     482            $old_settings = get_option('woocommerce_cod_settings');
     483
     484            // initialize a blank $settings array
     485            $settings = [];
     486            $settings['exchange_rates_enabled'] = 0;
     487            // check if old settings exist in native woocommerce cod options in woocommerce_cod_settings cell in wp_options
     488            if ( $old_settings && is_array($old_settings) ) {
     489           
     490                if ( array_key_exists('scffw_enable_on_cart', $old_settings) ) {
     491                    if ( $old_settings['scffw_enable_on_cart'] == 'yes' ) {
     492                        $settings['show_on_cart'] = true;
     493                    }
     494                    else {
     495                        $settings['show_on_cart'] = false;
     496                    }
     497                }
     498               
     499                if ( array_key_exists('fee_title', $old_settings) ) {
     500                    $settings['fee_title'] = $old_settings['fee_title'];
     501                }
     502       
     503                if ( array_key_exists('scffw_disable_cod_conditions', $old_settings) ) {
     504                    if ( $old_settings['scffw_disable_cod_conditions'] == 'yes' ) {
     505                        $settings['cod_conditionals'] = true;
     506                    }
     507                    else {
     508                        $settings['cod_conditionals'] = false;
     509                    }
     510                }
     511       
     512                if ( array_key_exists('scffw_disable_cod_if_less', $old_settings) ) {
     513                    $settings['cod_disable_min'] = $old_settings['scffw_disable_cod_if_less'];
     514                }
     515       
     516                if ( array_key_exists('scffw_disable_cod_if_greater', $old_settings) ) {
     517                    $settings['cod_disable_max'] = $old_settings['scffw_disable_cod_if_greater'];
     518                }
     519       
     520                if ( array_key_exists('scffw_disable_cod_fee_conditions', $old_settings) ) {
     521                    if ( $old_settings['scffw_disable_cod_fee_conditions'] == 'yes' ) {
     522                        $settings['cod_fee_conditionals'] = true;
     523                    }
     524                    else {
     525                        $settings['cod_fee_conditionals'] = false;
     526                    }
     527                }
     528       
     529                if ( array_key_exists('scffw_disable_cod_fee_if_less', $old_settings) ) {
     530                    $settings['cod_fee_disable_min'] = $old_settings['scffw_disable_cod_fee_if_less'];
     531                }
     532       
     533                if ( array_key_exists('scffw_disable_cod_fee_if_greater', $old_settings) ) {
     534                    $settings['cod_fee_disable_max'] = $old_settings['scffw_disable_cod_fee_if_greater'];
     535                }
     536       
     537                if ( array_key_exists('fee', $old_settings) ) {
     538                    $settings['cod_fee'] = $old_settings['fee'];
     539                }
     540       
     541                if ( array_key_exists('scffw_cod_fee_tax_status', $old_settings) ) {
     542                    if ( $old_settings['scffw_cod_fee_tax_status'] == 'taxable' ) {
     543                        $settings['enable_tax'] = true;
     544                    }
     545                    else {
     546                        $settings['enable_tax'] = false;
     547                    }
     548                }
     549               
     550                $shipping_zones         = WC_Shipping_Zones::get_zones();
     551                $shipping_option_names = [];
     552
     553                foreach ( $shipping_zones as $zone ) {
     554                    foreach ( $zone['shipping_methods'] as $shipping_method ) {
     555                        if ( scffw_shipping_method_is_enabled_for_cod_fee($shipping_method) ) {
     556                            $shipping_id = $shipping_method->id . '_' . $shipping_method->instance_id;
     557                           
     558                            $maybe_options = get_option('woocommerce_' . $shipping_id . '_settings');
     559                           
     560                            if ( function_exists( 'wcml_is_multi_currency_on' ) && wcml_is_multi_currency_on() ) {
     561                                foreach ( scffw_wpml_get_all_currencies() as $key => $currency ) {
     562                                    if ( array_key_exists('scffw_cod_fee_' . $currency, $maybe_options ) ) {
     563                                        $settings['shipping_methods_fees'][$shipping_id . '_' . mb_strtolower($currency)] = $maybe_options['scffw_cod_fee_' . $currency];
     564                                        $settings['different_fees_per_shipping_method_enabled'] = true;
     565                                    }
     566                                }
     567                            }
     568                            else {
     569
     570                            }
     571                        }
     572                    }
     573                }
     574
     575                unset($old_settings['scffw_enable_on_cart']);
     576                unset($old_settings['scffw_disable_cod_conditions']);
     577                unset($old_settings['scffw_disable_cod_if_greater']);
     578                unset($old_settings['scffw_disable_cod_if_less']);
     579                unset($old_settings['scffw_disable_cod_fee_conditions']);
     580                unset($old_settings['scffw_disable_cod_fee_if_greater']);
     581                unset($old_settings['scffw_disable_cod_fee_if_less']);
     582                unset($old_settings['fee']);
     583                unset($old_settings['scffw_cod_fee_tax_status']);
     584                unset($old_settings['scffw_cod_fee_tax_rates']);
     585                unset($old_settings['fee_title']);
     586               
     587                update_option('woocommerce_cod_settings', $old_settings, true);
     588                // if there is at least one setting in the $settings array enable the new settings
     589                $settings['enabled'] = true;
     590                update_option(SCFFW_COD_SETTINGS, $settings, false);
     591            }
     592        }
     593
     594        update_option(SCFFW_VERSION_OPTIONS, SCFFW_VERSION, false);
     595    }
     596});
Note: See TracChangeset for help on using the changeset viewer.