• Resolved Heikki

    (@heikkiwaan)


    Hello.

    I am developing a plugin that changes the currency display.

    But the problem is that the new displayed value is there only for around ~0.5 seconds.

    When i change the currency with url /?hh_currency=USD
    and /?hh_currency=EUR
    the displayed currency in the top navigation bar cart is only shown for ~0.5 seconds.

    If i add a product to the cart, it displays it ok after that.

    So how can i fix this?

    a screenshot of the error
    https://www.dropbox.com/s/x9mopdjsvtmbfnp/CurrencySwitching_not_working.png?dl=0

    screenshot 1 is shown when you come to the site
    screenshot 2 when you change the currency (url above)
    screenshot 3 is shown around ~0.5 seconds after changing the currency.
    should not go to the stage 3.

    i think some javascript reverts it back to the old value when changing the currency????

    WordPress 5.0.2
    Theme: StoreFront
    Installed plugins (2): WooComemrce, this test plugin.

    Here’s a TEST code to demonstrate the problem.

    <?php
    /**
     * @package heikin_test_currency
     * @version 0.1
     */
    /*
    Plugin Name: Heikin TESTIT - Currency
    Description: Testing some currency things
    Author: Me
    Version: 0.1
    */
    
    if (!defined('ABSPATH'))
    	exit;
    
    class hh_dual_currency_rates_test
    {
    	public function __construct()
    	{
    		add_action( 'init', array($this, 'process_get_post' ));
    
    		add_filter( 'woocommerce_get_price_html', array($this, 'custom_price_message' ));
    		add_filter( 'woocommerce_cart_item_price', array($this, 'custom_price_message' ));
    		add_filter( 'woocommerce_cart_item_subtotal', array($this, 'custom_price_message' ));
    		add_filter( 'woocommerce_cart_subtotal', array($this, 'custom_price_message' ));
    		add_filter( 'woocommerce_cart_total', array($this, 'custom_price_message' ));
    	}
    
    	function custom_price_message($price)
    	{
    		if ($_SESSION['hh_currency'] == "USD")
    			return '<span class="woocommerce-Price-amount amount">$12.34 USD-test</span>';
    		else
    			return $price;
    	}
    
    	function process_get_post()
    	{
    		if( !session_id() )
    			session_start();
    
    		if( isset( $_GET['hh_currency'] ) )
    		{
    			$_SESSION['hh_currency'] = preg_replace("/[^A-Z]/", "", $_GET['hh_currency']);
    			
    		}
    	}
    }
    
    global $hh_rates;
    $hh_rates = new hh_dual_currency_rates_test();
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Trying to modify currency display – Some javascript probably messes it up’ is closed to new replies.