Plugin Directory

Changeset 2902019


Ignore:
Timestamp:
04/20/2023 09:37:47 PM (3 years ago)
Author:
asofantzis
Message:

Added WPML Multilingual support

Location:
simple-cod-fee-for-woocommerce
Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • simple-cod-fee-for-woocommerce/trunk/custom-cod-payment.php

    r2900777 r2902019  
    6767             */
    6868            public function init_form_fields() {
     69                if ( function_exists( 'wcml_is_multi_currency_on' ) && wcml_is_multi_currency_on() && !empty(scffw_wpml_get_all_currencies()) ) {
     70                    foreach ( scffw_wpml_get_all_currencies() as $currency_code ) {
     71                        $fee_fields['scffw_cod_fee_' . $currency_code] = array(
     72                            'title'       => esc_html__( 'Extra COD fee', 'scffw' ) . ' - ' . $currency_code,
     73                            'type'        => 'text',
     74                            'placeholder' => __( 'eg. 2.3', 'woocommerce' ),
     75                            'default'     => 0,
     76                            'class'             => 'scffw-extra-cod-fee-settings-input',
     77                            // 'desc_tip'    => true,
     78                        );
     79                    }
     80                }
     81                else {
     82                    $fee_fields['fee'] = array(
     83                        'title'       => esc_html__( 'Extra COD fee', 'scffw' ),
     84                        'type'        => 'text',
     85                        'placeholder' => __( 'eg. 2.3', 'woocommerce' ),
     86                        'default'     => 0,
     87                        'class'             => 'scffw-extra-cod-fee-settings-input',
     88                        // 'desc_tip'    => true,
     89                    );
     90                }
    6991                $this->form_fields = array(
    7092                    'enabled'            => array(
     
    115137                        'default' => 'yes',
    116138                    ),
    117                     'fee'       => array(
    118                         'title'       => __( 'Fee', 'woocommerce' ),
    119                         'type'        => 'text',
    120                         'placeholder' => __( 'eg. 2.3', 'woocommerce' ),
    121                         'default'     => 0,
    122                         'class'             => 'scffw-extra-cod-fee-settings-input',
    123                         // 'desc_tip'    => true,
    124                     ),
    125139                    'fee_title'       => array(
    126140                        'title'       => __( 'Fee title', 'scffw' ),
     
    128142                        'description' => __( 'The label the user will see as extra fee', 'woocommerce' ),
    129143                        'placeholder' => __( 'eg. Extra COD fee', 'woocommerce' )
    130                     ),
     144                    )
    131145                );
     146
     147                // $this->form_fields['fee'] = $fee_fields;
     148                // array_push($this->form_fields, $fee_fields);
     149                foreach ( $fee_fields as $key => $field ) {
     150                    $this->form_fields[$key] = $field;
     151                }
    132152            }
    133153
  • simple-cod-fee-for-woocommerce/trunk/readme.txt

    r2900787 r2902019  
    17172. How the options are shown in frontend
    18183. Different cod fee for each shipping method
     194. Different cod fee for each currency per shipping method
    1920
    2021== Frequently Asked Questions ==
     
    2728
    2829== Changelog ==
     30
     31= 1.6 =
     32* Added WPML Multicurrency support
     33* If there is WPML Multicurrency enabled then different fields will show up to declare different fee per currency (currently not support exchange rates, only fixed fees)
    2934
    3035= 1.5 =
  • simple-cod-fee-for-woocommerce/trunk/scffw-admin.min.js

    r2900777 r2902019  
    1 !function($){$(document).on("change keyup paste",".scffw-extra-cod-fee-settings-input",(function(e){e.preventDefault();var t=$(".scffw-extra-cod-fee-settings-input").val().replace(",",".").replace(/[^0-9\.]/g,"");-1!=t.indexOf(".")&&t.split(".")[1].length>2&&(t=parseFloat(t).toFixed(2)),$(".scffw-extra-cod-fee-settings-input").val(t)}))}(jQuery);
     1!function($){$(document).on("change keyup paste",".scffw-extra-cod-fee-settings-input",(function(t){t.preventDefault(),$thisInput=$(this);var e=$thisInput.val().replace(",",".").replace(/[^0-9\.]/g,"");-1!=e.indexOf(".")&&e.split(".")[1].length>2&&(e=parseFloat(e).toFixed(2)),$thisInput.val(e)}))}(jQuery);
  • simple-cod-fee-for-woocommerce/trunk/simple-cod-fee-for-woocommerce.php

    r2900777 r2902019  
    6262    if ( $chosen_gateway != 'cod' )
    6363        return;
     64   
    6465
    6566    $payment_gateway = WC()->payment_gateways->payment_gateways()['cod'];
     
    125126               
    126127                add_filter( 'woocommerce_shipping_instance_form_fields_' .  $shipping_method->id, function ( $settings ) use ( $shipping_method ) {
    127                    
    128                     $settings['scffw_cod_fee'] = array(
    129                         'title'       => esc_html__( 'Extra COD fee', 'scffw' ),
    130                         'type'        => 'text',
    131                         'placeholder' => __( 'eg. 2.3', 'scffw' ),
    132                         'description' => esc_html__( 'Please add the cash on delivery cost for this shipping method, if left empty the default fee set in payment gateway will apply', 'scffw' ),
    133                         'class' => 'scffw-extra-cod-fee-settings-input scffw-' . $shipping_method->id . '-' . $shipping_method->get_instance_id(),
    134                         'desc_tip'    => true,
    135                         'default' => ''
    136                     );
     128                    if ( function_exists( 'wcml_is_multi_currency_on' ) && wcml_is_multi_currency_on() ) {
     129                        $currencies = scffw_wpml_get_all_currencies();
     130                       
     131                        if ( is_array($currencies) && !empty($currencies) ) {
     132                            foreach ( $currencies as $currency_code ) {
     133                                $settings['scffw_cod_fee_' . $currency_code] = array(
     134                                    'title'       => esc_html__( 'Extra COD fee', 'scffw' ) . ' - ' . $currency_code,
     135                                    'type'        => 'text',
     136                                    'placeholder' => __( 'eg. 2.3', 'scffw' ),
     137                                    'description' => esc_html__( 'Please add the cash on delivery cost for this shipping method, if left empty the default fee set in payment gateway will apply', 'scffw' ),
     138                                    'class' => 'scffw-extra-cod-fee-settings-input scffw-' . $shipping_method->id . '-' . $shipping_method->get_instance_id(),
     139                                    'desc_tip'    => true,
     140                                    'default' => ''
     141                                );
     142                            }
     143                        }
     144                       
     145                    }
     146                    else {
     147                        $settings['fee'] = array(
     148                            'title'       => esc_html__( 'Extra COD fee', 'scffw' ),
     149                            'type'        => 'text',
     150                            'placeholder' => __( 'eg. 2.3', 'scffw' ),
     151                            'description' => esc_html__( 'Please add the cash on delivery cost for this shipping method, if left empty the default fee set in payment gateway will apply', 'scffw' ),
     152                            'class' => 'scffw-extra-cod-fee-settings-input scffw-' . $shipping_method->id . '-' . $shipping_method->get_instance_id(),
     153                            'desc_tip'    => true,
     154                            'default' => ''
     155                        );
     156                    }
    137157
    138158                    return $settings;
     
    141161        }
    142162    }
    143 },100 );
     163}, 100 );
    144164
    145165function scffw_get_shipping_method_cod_fee($shipping_method_id, $index) {
     
    147167    $cod = WC()->payment_gateways->payment_gateways()['cod'];
    148168    $settings = get_option( 'woocommerce_' . $shipping_method_id . '_' . $index . '_settings' );
    149    
    150     if ( is_array($settings) && array_key_exists('scffw_cod_fee', $settings) && $settings['scffw_cod_fee'] != '' ) {
    151         return $settings['scffw_cod_fee'];
    152     }
    153 
    154    
     169
     170    // if wpml multicurrency is enabled
     171    if ( function_exists( 'wcml_is_multi_currency_on' ) && wcml_is_multi_currency_on() ) {
     172        $current_currency = get_woocommerce_currency();
     173       
     174        // if user has entered fees for each language
     175        if ( array_key_exists('scffw_cod_fee_' . $current_currency, $settings) ) {
     176            return $settings['scffw_cod_fee_' . $current_currency];
     177        }
     178        // get default cod fee
     179        elseif ( array_key_exists('scffw_cod_fee_' . $current_currency, $cod->settings) && $cod->settings['scffw_cod_fee_' . $current_currency] ) {
     180            return $cod->settings['scffw_cod_fee_' . $current_currency];
     181        }
     182       
     183    }
     184    // default no multicurrency
     185    else {
     186       
     187        if ( is_array($settings) && array_key_exists('fee', $settings) && $settings['fee'] != '' ) {
     188            return $settings['fee'];
     189        }
     190        elseif ( is_array($settings) && array_key_exists('fee', $cod->settings) && $cod->settings['fee'] != '' ) {
     191            return $cod->settings['fee'];
     192        }
     193    }
     194
    155195    return $cod->settings['fee'];
    156196}
     197
     198function scffw_wpml_get_all_currencies() {
     199    $wcml_options = get_option( '_wcml_settings' );
     200    $enabled_currencies = $wcml_options['currency_options'];
     201    $currencies = [];
     202
     203    foreach ( $enabled_currencies as $key => $currency ) {
     204        $currencies[] = $key;
     205    }
     206    return $currencies;
     207}
Note: See TracChangeset for help on using the changeset viewer.