English 中文(简体)
Call a function after geolocalization in Woocommerce
原标题:

I am using the plugin FOX – Currency Switcher Professional for WooCommerce (former name is WOOCS) and everything was working smoothly. Then I have installed a budgeter plugin. Unfortunately, it is not multicurrency and not compatible with the Currency Switcher.

Therefore, I had to create two instances of the budgeter: one for Argentine pesos and another for dollars. These two instances are loaded on the same page,"/prices/", and from the Divi Builder create two code modules that display according to a conditional: if the "ARS" parameter of currency exists in the URL, display the module that has the shortcode of the budget in pesos; instead, if there is "USD" as a currency parameter in the URL, then hide the other one and load the budgeter in dollars.

In the WOOCS module I have geolocation activated, and it takes ARS only for Argentina, for the rest of the countries it takes dollars.

But sometimes works and sometimes not. Recently, I have checked it three times: Argentina (worked), EU (worked), Argentina again (worked), Brasil (didn t work). They were all consecutive tests: Changing the location on the VPN, checking the IP at whatismyipaddress.com and then opening a new incognito window.

I ve not caching plugins enabled.

This is the code I have installed on my site to add the currency parameter:

function agregar_moneda_a_url() {
    global $WOOCS;
    
    $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $parsed_url = parse_url($current_url);

    if (isset($parsed_url[ query ]) && !empty($parsed_url[ query ])) {
        $params = [];
        parse_str($parsed_url[ query ], $params);
        
        if (isset($params[ currency ])) {
            return; // El parámetro"currency" ya está presente en la URL, no se hace nada
        }
    }
    if (is_page( precios )) {
        $moneda = $WOOCS->current_currency;
        $new_url = add_query_arg( currency , $moneda, $current_url);
        wp_redirect($new_url);
        exit;
    }
}
add_action( template_redirect ,  agregar_moneda_a_url );

As you can see, when it doesn t work, the URL takes the value of currency configured as initial in the plugin options, not the one it should according to the geolocation. However, the currency exchanger is taking the value of currency according to the geolocation.

I understand that I am close to the solution, but I must be loading the code at the wrong time, right? If it loaded the code at the same time or after the multi-currency plugin takes the geolocation value, then it should take the correct value from WOOCS variable.

If you could guide me with this, I would really appreciate it.

问题回答

暂无回答




相关问题
Currency Conversion Web Service With User Input

I want to Consume a Currency Conversion Web service, Specification is, User should be able to Select Two Countries from Dropdown list on the UI, such that those values should be sent as parameters to ...

Currency modeling in database

A very naive question. I need to store currency in the database. Both the value and the code. To solve this, do people generally make 2 columns, one storing the value and other the code? Or is there ...

Formatting of BDC Fields

I m trying to format a field in a BDC (Business Data Catalog) definition, in SharePoint, with a thousand separator. It doesn t appear to be possible in the BDC XML definition, and only possible ...

String representation of small amounts of money

Formatting large amounts of money is not an issue (e.g. converting a decimal to dollars): myDecimal.ToString("C", {some culture info}); However, my current problem is dealing with very small amounts ...

convert currency from xml + php

I have an xml source for daily currency http://www.tcmb.gov.tr/kurlar/today.xml and i need to make a currency optional search for a portal. how can I get a specific data and convert from xml source? ...

热门标签