Changeset 2911261
- Timestamp:
- 05/11/2023 03:39:14 PM (3 years ago)
- Location:
- simple-cod-fee-for-woocommerce
- Files:
-
- 11 added
- 4 edited
-
tags/1.7 (added)
-
tags/1.7/custom-cod-payment.php (added)
-
tags/1.7/languages (added)
-
tags/1.7/languages/scffw-el.mo (added)
-
tags/1.7/languages/scffw-el.po (added)
-
tags/1.7/readme.txt (added)
-
tags/1.7/scffw-admin.min.js (added)
-
tags/1.7/scffw.css (added)
-
tags/1.7/scffw.min.js (added)
-
tags/1.7/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/scffw.css (added)
-
trunk/simple-cod-fee-for-woocommerce.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-cod-fee-for-woocommerce/trunk/custom-cod-payment.php
r2902019 r2911261 67 67 */ 68 68 public function init_form_fields() { 69 69 70 if ( function_exists( 'wcml_is_multi_currency_on' ) && wcml_is_multi_currency_on() && !empty(scffw_wpml_get_all_currencies()) ) { 70 71 foreach ( scffw_wpml_get_all_currencies() as $currency_code ) { … … 89 90 ); 90 91 } 92 93 $tax_rates = scffw_get_all_standard_tax_rates(); 94 95 // only show taxable option if there is at least one standard tax option 96 if ( is_array($tax_rates) && !empty($tax_rates) ) { 97 // tax status 98 $fee_fields['scffw_cod_fee_tax_status'] = array( 99 'title' => esc_html__( 'Extra COD fee Tax Status', 'scffw' ), 100 'type' => 'select', 101 'options' => [ 102 'taxable' => __('Taxable', 'woocommerce'), 103 'none' => __('None', 'woocommerce') 104 ], 105 'default' => 'none', 106 'class' => 'cod-fee-tax-status-select' 107 ); 108 109 $tax_rates_options = []; 110 111 foreach ( $tax_rates as $tax ) { 112 $tax_rates_options[$tax['rate']] = $tax['label'] . ' - ' . $tax['rate'] . '%'; 113 } 114 115 // all standard tax rates 116 $fee_fields['scffw_cod_fee_tax_rates'] = array( 117 'title' => esc_html__( 'Select Tax', 'scffw' ), 118 'type' => 'select', 119 'options' => $tax_rates_options, 120 'default' => 'none', 121 'class' => 'cod-fee-tax-rates-select' 122 ); 123 } 124 91 125 $this->form_fields = array( 92 126 'enabled' => array( … … 141 175 'type' => 'text', 142 176 'description' => __( 'The label the user will see as extra fee', 'woocommerce' ), 143 'placeholder' => __( 'eg. Extra COD fee', 'woocommerce' ) 144 ) 177 'placeholder' => __( 'eg. Extra COD fee', 'woocommerce' ), 178 ), 179 'scffw_enable_on_cart' => array( 180 'title' => __( 'Show COD fee on cart page?', 'scffw' ), 181 'label' => __( 'Show the extra fee on cart page', 'scffw' ), 182 'type' => 'checkbox', 183 'default' => 'yes', 184 ), 185 'scffw_disable_cod_conditions' => array( 186 'title' => __( 'Completely disable COD depending on cart total', 'scffw' ), 187 'label' => __('Enable this option to completely remove <strong>COD</strong> as payment method if cart total is less/more than a specific amount', 'pfw'), 188 'type' => 'checkbox', 189 'default' => 'no', 190 'class' => 'disable-cod-conditionals' 191 ), 192 'scffw_disable_cod_if_greater' => array( 193 'title' => __( 'Disable COD if more than', 'scffw' ), 194 'description' => __( 'Disable COD if cart subtotal is more than this amount', 'scffw' ), 195 'type' => 'text', 196 'class' => 'disable-cod-if-greater' 197 ), 198 'scffw_disable_cod_if_less' => array( 199 'title' => __( 'Disable COD if less than', 'scffw' ), 200 'description' => __( 'Disable COD if cart subtotal is less than this amount', 'scffw' ), 201 'type' => 'text', 202 'class' => 'disable-cod-if-less' 203 ), 204 'scffw_disable_cod_fee_conditions' => array( 205 'title' => __( 'Completely disable Extra Fee?', 'scffw' ), 206 'label' => __( 'Enable this option to remove <strong>COD Fee</strong> if cart subtotal is less/more than a specific amount', 'scffw' ), 207 'type' => 'checkbox', 208 'default' => 'no', 209 'class' => 'disable-cod-fee-conditionals' 210 ), 211 'scffw_disable_cod_fee_if_greater' => array( 212 'title' => __( 'Disable fee if more than', 'scffw' ), 213 'description' => __( 'Disable COD Fee if cart subtotal is more than this amount', 'scffw' ), 214 'type' => 'text', 215 'default' => 0, 216 'class' => 'disable-cod-fee-if-greater' 217 ), 218 'scffw_disable_cod_fee_if_less' => array( 219 'title' => __( 'Disable fee if less than', 'scffw' ), 220 'description' => __( 'Disable COD Fee if cart subtotal is less than this amount', 'scffw' ), 221 'type' => 'text', 222 'default' => 0, 223 'class' => 'disable-cod-fee-if-less' 224 ), 145 225 ); 146 226 147 // $this->form_fields['fee'] = $fee_fields;148 // array_push($this->form_fields, $fee_fields);149 227 foreach ( $fee_fields as $key => $field ) { 150 228 $this->form_fields[$key] = $field; -
simple-cod-fee-for-woocommerce/trunk/readme.txt
r2902023 r2911261 5 5 Tested up to: 6.2 6 6 Requires PHP: 7.0 7 Stable tag: 1. 67 Stable tag: 1.7 8 8 License: GPLv2 or later 9 9 … … 28 28 = Does this plugin work with WPML and multiple currencies? 29 29 Yes, if you use WPML and have multicurrency support enabled, you can now have multiple COD fee per currency. Currently only fixed fees are support and not exchange rates. 30 = Does this plugin offers an option to Disable COD or COD Fee depending on user's cart subtotal? 31 Yes, you can configure this plugin to disable either COD or COD Fee depending on user's total amount in cart 32 == Changelog == 30 33 31 == Changelog == 34 = 1.7 = 35 * **FIXED** when sometimes if WPML was enabled, some payment methods disappeared from admin menu 36 * Added option to enable tax status for the extra cod fee 37 * Added option to completely remove COD or COD Fee if cart subtotal is less/more than a specific amount 32 38 33 39 = 1.6 = -
simple-cod-fee-for-woocommerce/trunk/scffw-admin.min.js
r2902019 r2911261 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);1 !function($){function e(){"taxable"==$(".cod-fee-tax-status-select option:selected").val()?$(".cod-fee-tax-rates-select").parents("tr").show():$(".cod-fee-tax-rates-select").parents("tr").hide()}$(document).on("change keyup paste",".scffw-extra-cod-fee-settings-input",(function(e){e.preventDefault(),$thisInput=$(this);var t=$thisInput.val().replace(",",".").replace(/[^0-9\.]/g,"");-1!=t.indexOf(".")&&t.split(".")[1].length>2&&(t=parseFloat(t).toFixed(2)),$thisInput.val(t)})),$(".disable-cod-if-greater").length&&$(".disable-cod-if-greater").parents("tr").addClass("scffw-cod-conditionals"),$(".disable-cod-if-less").length&&$(".disable-cod-if-less").parents("tr").addClass("scffw-cod-conditionals"),$(".disable-cod-fee-if-greater").length&&$(".disable-cod-fee-if-greater").parents("tr").addClass("scffw-cod-fee-conditionals"),$(".disable-cod-fee-if-less").length&&$(".disable-cod-fee-if-less").parents("tr").addClass("scffw-cod-fee-conditionals"),$(".disable-cod-conditionals").is(":checked")||($(".disable-cod-if-greater").parents("tr").hide(),$(".disable-cod-if-less").parents("tr").hide()),$(".disable-cod-fee-conditionals").is(":checked")||($(".disable-cod-fee-if-greater").parents("tr").hide(),$(".disable-cod-fee-if-less").parents("tr").hide()),$(document).on("change",".disable-cod-conditionals",(function(){$(this).is(":checked")?($(".disable-cod-if-greater").parents("tr").fadeIn(),$(".disable-cod-if-less").parents("tr").fadeIn()):($(".disable-cod-if-greater").parents("tr").fadeOut(),$(".disable-cod-if-less").parents("tr").fadeOut())})),$(document).on("change",".disable-cod-fee-conditionals",(function(){$(this).is(":checked")?($(".disable-cod-fee-if-greater").parents("tr").fadeIn(),$(".disable-cod-fee-if-less").parents("tr").fadeIn()):($(".disable-cod-fee-if-greater").parents("tr").fadeOut(),$(".disable-cod-fee-if-less").parents("tr").fadeOut())})),$(".cod-fee-tax-status-select").length&&(e(),$(document).on("change",".cod-fee-tax-status-select",(function(){e()})))}(jQuery); -
simple-cod-fee-for-woocommerce/trunk/simple-cod-fee-for-woocommerce.php
r2902022 r2911261 3 3 Plugin Name: Simple COD Fee for WooCommerce 4 4 Description: Simply add extra fee for WooCommerce Cash On Delivery payment method 5 Version: 1. 65 Version: 1.7 6 6 Author: Andreas Sofantzis 7 7 Author URI: https://83pixel.com … … 42 42 add_filter( 'woocommerce_payment_gateways', function( $gateways ) { 43 43 $search = array_search('WC_Gateway_COD', $gateways); 44 45 // WPML is converting payment gateways to objects so we first check if array elements are text or objects, if objects WPML is enabled 46 47 // WPML is not active 48 if ( $search ) { 49 unset($gateways[$search]); 50 $gateways = array_values($gateways); 51 52 // enable custom COD 53 $gateways[] = 'WC_Gateway_COD2'; 54 } 55 else { 56 foreach ($gateways as $key => $gateway) { 57 // Check if it is the Cash on Delivery (COD) gateway 58 if ($gateway->id === 'cod') { 59 // Disable Cash on Delivery (COD) payment gateway 60 unset($gateways[$key]); 61 $gateways[] = 'WC_Gateway_COD2'; 62 break; // Exit the loop after disabling the gateway 63 } 64 } 65 } 44 66 // unset default COD 45 unset($gateways[$search]); 46 $gateways = array_values($gateways); 47 48 // enable custom COD 49 $gateways[] = 'WC_Gateway_COD2'; 67 50 68 return $gateways; 51 69 },100 ); … … 68 86 $chosen_shipping_methods = wc_get_chosen_shipping_method_ids(); 69 87 88 $show_on_cart = $payment_gateway->settings['scffw_enable_on_cart']; 89 90 if ( is_cart() && $show_on_cart != 'yes' ) { 91 return; 92 } 93 70 94 $fee_title = $payment_gateway->settings['fee_title'] ?: __('COD Fee', 'scffw'); 71 95 $chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' ); 72 96 $enabled_cod_shipping_methods = $payment_gateway->settings['enable_for_methods']; 73 97 74 98 // if COD is enabled for some shipping methods 75 99 if ( !empty( $enabled_cod_shipping_methods ) ) { 76 100 if (!empty( array_intersect($chosen_shipping_method, $enabled_cod_shipping_methods) ) ) { 77 78 101 79 102 $chosen_method_object = explode(':', array_intersect($chosen_shipping_method, $enabled_cod_shipping_methods)[0]); … … 174 197 // if user has entered fees for each language 175 198 if ( array_key_exists('scffw_cod_fee_' . $current_currency, $settings) ) { 176 return$settings['scffw_cod_fee_' . $current_currency];199 $fee = $settings['scffw_cod_fee_' . $current_currency]; 177 200 } 178 201 // get default cod fee 179 202 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];203 $fee = $cod->settings['scffw_cod_fee_' . $current_currency]; 181 204 } 182 205 … … 184 207 // default no multicurrency 185 208 else { 186 209 // if selected shipping method has specific cod fee 187 210 if ( is_array($settings) && array_key_exists('fee', $settings) && $settings['fee'] != '' ) { 188 return $settings['fee']; 189 } 211 $fee = $settings['fee']; 212 } 213 // if selected shipping method uses default cod fee 190 214 elseif ( is_array($settings) && array_key_exists('fee', $cod->settings) && $cod->settings['fee'] != '' ) { 191 return $cod->settings['fee']; 192 } 193 } 194 195 return $cod->settings['fee']; 215 $fee = $cod->settings['fee']; 216 } 217 } 218 219 if ( $cod->settings['scffw_cod_fee_tax_status'] == 'taxable' && is_checkout() ) { 220 221 $tax_percentage = $cod->settings['scffw_cod_fee_tax_rates']; 222 $fee = $fee + ( $fee * $tax_percentage / 100); 223 } 224 225 if ( is_checkout() || is_cart() ) { 226 $cart = WC()->cart; 227 if ( $cod->settings['scffw_disable_cod_fee_conditions'] == 'yes' ) { 228 $cart_subtotal = $cart->get_subtotal(); 229 if ( $cart_subtotal > $cod->settings['scffw_disable_cod_fee_if_greater'] || $cart_subtotal < $cod->settings['scffw_disable_cod_fee_if_less'] ) { 230 $fee = 0; 231 } 232 } 233 } 234 235 return $fee; 236 196 237 } 197 238 … … 206 247 return $currencies; 207 248 } 249 250 add_action( 'admin_enqueue_scripts', function() 251 { 252 // Styles 253 wp_enqueue_style( 254 'scffw', 255 plugin_dir_url( __FILE__ ) . 'scffw.css', 256 array(), 257 filemtime(plugin_dir_path( __FILE__ ) . 'scffw.css') 258 ); 259 }); 260 261 function scffw_get_all_standard_tax_rates() { 262 $tax_instance = new WC_Tax(); 263 264 // Get all tax rates 265 $tax_rates = $tax_instance->get_rates(); 266 267 return $tax_rates; 268 } 269 270 add_filter('woocommerce_available_payment_gateways', function($available_gateways) { 271 if ( is_checkout() || is_cart() ) { 272 $cod = $available_gateways['cod']; 273 if ( $cod->settings['scffw_disable_cod_conditions'] == 'yes' ) { 274 $cart = WC()->cart; 275 276 $cart_subtotal = $cart->get_subtotal(); 277 if ( $cart_subtotal > $cod->settings['scffw_disable_cod_if_greater'] || $cart_subtotal < $cod->settings['scffw_disable_cod_if_less'] ) { 278 unset($available_gateways['cod']); 279 } 280 } 281 } 282 283 return $available_gateways; 284 });
Note: See TracChangeset
for help on using the changeset viewer.