Plugin Directory

Changeset 953689


Ignore:
Timestamp:
07/23/2014 07:55:10 PM (12 years ago)
Author:
ctala
Message:

Agregando el OpenExchange Rate para ver el valor en dolares para pago paypal.

Location:
woocommerce-chilean-peso-currency/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-chilean-peso-currency/trunk/readme.txt

    r795902 r953689  
    1111Tested up to: 3.6
    1212
    13 Stable tag: 2.4.1
     13Stable tag: 2.5
    1414
    1515== Description ==
     
    3030== Changelog ==
    3131
     32= 2.5 =
     33
     34* Conexión a OpenExchange Rates para tener el valor del dolar actualizado.
     35* Se hace cache del valor del dolar para ahorrar consultas.
     36
    3237= 2.4 =
    3338
    34 Se deshabilita el código postal como obligatorio.
     39* Se deshabilita el código postal como obligatorio.
    3540
    3641= 2.2 =
    37 Agregada la posibilidad de usar paypal con woocommerce y chilean pesos.
     42* Agregada la posibilidad de usar paypal con woocommerce y chilean pesos.
    3843
    3944= 2.0 =
    40 Added the Chilean states for WooCommerce
    41 Agregadas las Regiones de Chile a WooCommerce
     45* Added the Chilean states for WooCommerce
     46* Agregadas las Regiones de Chile a WooCommerce
  • woocommerce-chilean-peso-currency/trunk/woocommerce-chilean-peso.php

    r795902 r953689  
    44  Plugin Name: WooCommerce Chilean Peso + Chilean States
    55  Plugin URI: http://plugins.svn.wordpress.org/woocommerce-chilean-peso-currency/
    6   Description: This plugin add the chilean currency, symbol , paypal and the states to WooCommerce.
    7   Version: 2.4.1
     6  Description: This plugin enables the payment with paypal for Chile and the Chilean states to WooCommerce.
     7  Version: 2.5
    88  Author: Cristian Tala Sánchez <cristian.tala@gmail.com>
    99  Author URI: http://www.cristiantala.cl
    1010  License: GPLv3
    1111  Requires at least: 3.0 +
    12   Tested up to: 3.7.1
     12  Tested up to: 3.9.1
    1313 */
    1414/*
     
    3232
    3333function add_clp_currency($currencies) {
     34
    3435    $currencies["CLP"] = 'Pesos Chilenos';
    3536    return $currencies;
     
    6768}
    6869
    69 
    70     function add_clp_paypal_valid_currency( $currencies ) { 
    71      array_push ( $currencies , 'CLP' );
    72      return $currencies; 
    73     }
    74 
    75 
    76 function convert_clp_to_usd($paypal_args){
    77     if ( $paypal_args['currency_code'] == 'CLP'){
    78         $convert_rate = 520; //set the converting rate
    79         $paypal_args['currency_code'] = 'USD'; //change CLP to USD
    80         $i = 1;
    81 
    82         while (isset($paypal_args['amount_' . $i])) {
    83             $paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
    84             ++$i;
    85         }
    86 
    87     }
    88 return $paypal_args;
     70function add_clp_paypal_valid_currency($currencies) {
     71    array_push($currencies, 'CLP');
     72    return $currencies;
    8973}
    9074
     75/*
     76 * Hace el cambio del valor a dolares a través de OpenExchange
     77 * Se necesita tener curl instalado para que esto funcione.
     78 */
     79
     80function convert_clp_to_usd($paypal_args) {
     81    if ($paypal_args['currency_code'] == 'CLP') {
     82
     83        $valorDolar = wp_cache_get('clp_usd_ctala');
     84        if (false === $valorDolar) {
     85            if (function_exists('curl_version')) {
     86                $file = 'latest.json';
     87                $appId = '3d2f0769c4fc42278faffd3933a23dd6';
     88                $url = "http://openexchangerates.org/api/$file?app_id=$appId";
     89// Open CURL session:
     90                $ch = curl_init($url);
     91                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     92
     93// Get the data:
     94                $json = curl_exec($ch);
     95                curl_close($ch);
     96
     97// Decode JSON response:
     98                $exchangeRates = json_decode($json);
     99                $valorDolar = $exchangeRates->rates->CLP;
     100            } else {
     101               $valorDolar = 580; // Este es el valor por defecto.
     102            }
     103            wp_cache_set('clp_usd_ctala', $valorDolar);
     104        }
     105
     106        $convert_rate = $valorDolar; //set the converting rate
     107        $paypal_args['currency_code'] = 'USD'; //change CLP to USD
     108        $i = 1;
     109
     110        while (isset($paypal_args['amount_' . $i])) {
     111            $paypal_args['amount_' . $i] = round($paypal_args['amount_' . $i] / $convert_rate, 2);
     112            ++$i;
     113        }
     114    }
     115    return $paypal_args;
     116}
    91117
    92118// Se eliminan los datos postales como obligatorios.
    93 function postalcode_override_default_address_fields( $address_fields ) {
    94      $address_fields['postcode']['required'] = false;
     119function postalcode_override_default_address_fields($address_fields) {
     120    $address_fields['postcode']['required'] = false;
    95121
    96      return $address_fields;
     122    return $address_fields;
    97123}
    98124
    99125//Se eliminan los códigos portales como obligatorios. (Filtro)
    100 add_filter( 'woocommerce_default_address_fields' , 'postalcode_override_default_address_fields' );
     126add_filter('woocommerce_default_address_fields', 'postalcode_override_default_address_fields');
    101127
    102128add_filter('woocommerce_paypal_args', 'convert_clp_to_usd');
     
    104130add_filter('woocommerce_currencies', 'add_clp_currency', 10, 1);
    105131add_filter('woocommerce_currency_symbol', 'add_clp_currency_symbol', 10, 2);
    106 add_filter( 'woocommerce_paypal_supported_currencies', 'add_clp_paypal_valid_currency' );     
     132add_filter('woocommerce_paypal_supported_currencies', 'add_clp_paypal_valid_currency');
    107133?>
Note: See TracChangeset for help on using the changeset viewer.