Viewing 9 replies - 1 through 9 (of 9 total)
  • Wil

    (@limecanvas)

    While waiting for an official fix you can do the following:

    Open up gravity-forms-multi-currency.php

    Replace all references of:
    $form[‘currency’]

    with
    $form[‘custom_currency’]

    There are 13 references. Should work after that.

    Wil.

    Hi there,

    I did the replacement, but only found 12 references?

    It seems to work perfectly except that the form total field displays the base currency?

    Any suggestions?

    Wil

    (@limecanvas)

    Hey Zane,

    As of v1.7 I get 13 occurrences.

    Here’s my fixed file.

    <?php
    /**
     * Plugin Name: Gravity Forms Multi Currency
     * Plugin URI: https://github.com/ilanco/gravity-forms-multi-currency
     * Description: Per form currency for Gravity Forms.
     * Version: 1.7
     * Author: Ilan Cohen <ilanco@gmail.com>
     * Author URI: https://github.com/ilanco
     */
    
    if (defined('WP_DEBUG') && (WP_DEBUG == true)) {
      error_reporting(E_ALL);
    }
    
    // don't load directly
    if (!defined('ABSPATH'))
      die(false);
    
    define('GF_MC_VERSION', '1.7');
    
    define('GF_MC_MAINFILE', __FILE__);
    
    add_action('init', array('GFMultiCurrency', 'init'), 9);
    
    class GFMultiCurrency
    {
        private static $instance;
    
        private $currency;
    
        private function __construct()
        {
            if (!$this->is_gravityforms_supported()) {
                return false;
            }
    
            add_action('wp', array(&$this, 'form_process'), 8);
            add_filter('gform_currency', array(&$this, 'form_currency'));
    
            if (is_admin()) {
                add_action('gform_admin_pre_render', array(&$this, 'admin_pre_render'));
                add_filter('gform_form_settings', array(&$this, 'custom_form_settings'), 10, 2);
                add_filter('gform_pre_form_settings_save', array(&$this, 'save_custom_form_settings'));
                add_action('gform_editor_js', array(&$this, 'admin_editor_js'));
    
                add_action('gform_entry_detail_content_before', array(&$this, 'admin_entry_detail'), 10, 2);
            }
            else {
                add_filter('gform_pre_render', array(&$this, 'pre_render'));
            }
        }
    
        public static function init()
        {
            if (!self::$instance) {
                self::$instance = new GFMultiCurrency();
            }
    
            return self::$instance;
        }
    
        public function form_process()
        {
            $form_id = isset($_POST["gform_submit"]) ? $_POST["gform_submit"] : 0;
    
            if ($form_id) {
                $form_info = RGFormsModel::get_form($form_id);
                $is_valid_form = $form_info && $form_info->is_active;
                if ($is_valid_form) {
                    $form = RGFormsModel::get_form_meta($form_id);
                    if (isset($form['custom_currency']) && $form['custom_currency']) {
                        $this->currency = $form['custom_currency'];
                    }
                }
            }
        }
    
        public function form_currency($currency)
        {
            if ($this->currency) {
                $currency = $this->currency;
            }
    
            return $currency;
        }
    
        public function admin_pre_render($form)
        {
            if (isset($form['custom_currency']) && $form['custom_currency']) {
                $this->currency = $form['custom_currency'];
            }
    
            return $form;
        }
    
        public function custom_form_settings($settings, $form)
        {
            ob_start();
            include 'tpl/custom_form_settings.php';
            $settings['Form Basics']['form_custom_currency_setting'] = ob_get_contents();
            ob_end_clean();
    
            return $settings;
        }
    
        public function save_custom_form_settings($form)
        {
            $form['custom_currency'] = rgpost('form_custom_currency');
    
            return $form;
        }
    
        public function admin_editor_js()
        {
            ?>
            <script type='text/javascript'>
            jQuery(function($) {
                $("#form_custom_currency").change(function() {
                    form.currency = this.value;
                });
                $("#form_custom_currency").val(form.currency);
            });
            </script>
            <?php
        }
    
        public function admin_entry_detail($form, $lead)
        {
            if (isset($form['custom_currency']) && $form['custom_currency']) {
                $this->currency = $form['custom_currency'];
            }
    
            return $form;
        }
    
        public function pre_render($form)
        {
            if (isset($form['custom_currency']) && $form['custom_currency']) {
                $this->currency = $form['custom_currency'];
            }
    
            return $form;
        }
    
        protected function gf_get_default_currency()
        {
            $currency = get_option("rg_gforms_currency");
            $currency = empty($currency) ? "USD" : $currency;
    
            return $currency;
        }
    
        private function is_gravityforms_supported()
        {
            if (class_exists("GFCommon")) {
                return true;
            }
    
            return false;
        }
    
        private function set_currency($form_id, $currency)
        {
            $this->currency[$form_id] = $currency;
        }
    
        private function get_currency($form_id)
        {
            return $this->currency[$form_id];
        }
    }

    Very odd. I downloaded the plugin again today and got 12 instances. Anyway, thanks for the fixed file 🙂

    I think my problem is coming in because I have two forms each with different currencies on one page.

    The second forms products use to pick up the currency from the first form. The fix you provided works great allowing both forms to now use their specified currencies.

    However the form total field still seems to carry over the currency from the first form 🙁

    Any way to overcome this?

    Wil

    (@limecanvas)

    Oooo – that’s a tricky one.

    You could try to badger around with the init() function in GFMC.

    Currently it’s set to detect if there is already an instance of itself and return the object if it is.

    Try removing the test for self::$instance and see what happens.

    Could lead to weird stuff though.

    Let me know how you go.

    Awesome. Will poke around and see what happens.

    Anonymous User 7600456

    (@anonymized-7600456)

    Hey guys this helped me. Thanks!

    Plugin Author ilanco

    (@ilanco)

    Sorry about the delay, i have updated the plugin and fixed the bug.

    Thanks to LimeCanvas for pointing out the bug.

    Wil

    (@limecanvas)

    Cheerz ilanco

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Plugin doesn't work with Gravity Forms v1.7.7’ is closed to new replies.