Changeset 2902019
- Timestamp:
- 04/20/2023 09:37:47 PM (3 years ago)
- Location:
- simple-cod-fee-for-woocommerce
- Files:
-
- 10 added
- 4 edited
-
assets/screenshot-4.jpg (added)
-
tags/1.6 (added)
-
tags/1.6/custom-cod-payment.php (added)
-
tags/1.6/languages (added)
-
tags/1.6/languages/scffw-el.mo (added)
-
tags/1.6/languages/scffw-el.po (added)
-
tags/1.6/readme.txt (added)
-
tags/1.6/scffw-admin.min.js (added)
-
tags/1.6/scffw.min.js (added)
-
tags/1.6/simple-cod-fee-for-woocommerce.php (added)
-
trunk/custom-cod-payment.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/scffw-admin.min.js (modified) (1 diff)
-
trunk/simple-cod-fee-for-woocommerce.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-cod-fee-for-woocommerce/trunk/custom-cod-payment.php
r2900777 r2902019 67 67 */ 68 68 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 } 69 91 $this->form_fields = array( 70 92 'enabled' => array( … … 115 137 'default' => 'yes', 116 138 ), 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 ),125 139 'fee_title' => array( 126 140 'title' => __( 'Fee title', 'scffw' ), … … 128 142 'description' => __( 'The label the user will see as extra fee', 'woocommerce' ), 129 143 'placeholder' => __( 'eg. Extra COD fee', 'woocommerce' ) 130 ) ,144 ) 131 145 ); 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 } 132 152 } 133 153 -
simple-cod-fee-for-woocommerce/trunk/readme.txt
r2900787 r2902019 17 17 2. How the options are shown in frontend 18 18 3. Different cod fee for each shipping method 19 4. Different cod fee for each currency per shipping method 19 20 20 21 == Frequently Asked Questions == … … 27 28 28 29 == 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) 29 34 30 35 = 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 62 62 if ( $chosen_gateway != 'cod' ) 63 63 return; 64 64 65 65 66 $payment_gateway = WC()->payment_gateways->payment_gateways()['cod']; … … 125 126 126 127 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 } 137 157 138 158 return $settings; … … 141 161 } 142 162 } 143 }, 100 );163 }, 100 ); 144 164 145 165 function scffw_get_shipping_method_cod_fee($shipping_method_id, $index) { … … 147 167 $cod = WC()->payment_gateways->payment_gateways()['cod']; 148 168 $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 155 195 return $cod->settings['fee']; 156 196 } 197 198 function 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.