Skip to content

Commit 3ee5f11

Browse files
committed
Added CIF features
1 parent 4e88f08 commit 3ee5f11

16 files changed

Lines changed: 963 additions & 259 deletions

README.md

Lines changed: 88 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -163,37 +163,60 @@ Total $203.50
163163

164164
#### Filters
165165

166-
```
167-
// Modify calculated fee amount
168-
add_filter( 'cfwc_calculated_fee', function( $fee, $product, $rule ) {
169-
// Custom fee logic
166+
```php
167+
// Modify all calculated fees before they're applied
168+
add_filter( 'cfwc_calculated_fees', function( $fees, $destination_country, $cart ) {
169+
// Modify fees array
170+
return $fees;
171+
}, 10, 3 );
172+
173+
// Modify a single fee calculation
174+
add_filter( 'cfwc_calculated_single_fee', function( $fee, $rule, $total ) {
175+
// Apply 50% discount for orders over $1000
176+
if ( WC()->cart->subtotal > 1000 ) {
177+
$fee = $fee * 0.5;
178+
}
170179
return $fee;
171180
}, 10, 3 );
172181

173-
// Customize fee label
174-
add_filter( 'cfwc_fee_label', function( $label, $rule ) {
182+
// Customize fee label displayed at checkout
183+
add_filter( 'cfwc_fee_label', function( $label, $rule, $country, $origin ) {
175184
return $label . ' (Estimated)';
176-
}, 10, 2 );
185+
}, 10, 4 );
177186

178-
// Override product origin
179-
add_filter( 'cfwc_product_origin', function( $origin, $product_id ) {
180-
// Custom origin logic
187+
// Override product origin country
188+
add_filter( 'cfwc_product_origin', function( $origin, $product_id, $product ) {
189+
// Force all electronics to use CN origin
190+
if ( has_term( 'electronics', 'product_cat', $product_id ) ) {
191+
return 'CN';
192+
}
181193
return $origin;
182-
}, 10, 2 );
194+
}, 10, 3 );
195+
196+
// Modify customs value (for CIF calculations)
197+
add_filter( 'cfwc_customs_value', function( $customs_value, $line_total, $cart_item, $method ) {
198+
// Force FOB for US/Canada even if CIF is enabled
199+
$destination = WC()->customer->get_shipping_country();
200+
if ( in_array( $destination, array( 'US', 'CA' ), true ) ) {
201+
return $line_total;
202+
}
203+
return $customs_value;
204+
}, 10, 4 );
205+
206+
// Provide insurance value for CIF calculations
207+
add_filter( 'cfwc_insurance_value', function( $insurance_value, $product_value, $method ) {
208+
// Add 2% insurance to all products
209+
return $product_value * 0.02;
210+
}, 10, 3 );
183211
```
184212

185213
#### Actions
186214

187-
```
188-
// After fees are calculated
189-
add_action( 'cfwc_after_calculate_fees', function( $fees, $cart ) {
190-
// Log or process calculated fees
191-
}, 10, 2 );
192-
193-
// After rule is saved
194-
add_action( 'cfwc_rule_saved', function( $rule_id, $rule_data ) {
195-
// Sync with external system
196-
}, 10, 2 );
215+
```php
216+
// After cache is cleared
217+
add_action( 'cfwc_cache_cleared', function() {
218+
// Perform cleanup or sync
219+
} );
197220
```
198221

199222
### Database schema
@@ -223,24 +246,31 @@ CREATE TABLE {prefix}cfwc_rules (
223246

224247
### With Multi-Currency Plugins
225248

226-
```
227-
// Fees automatically convert to displayed currency
228-
add_filter('cfwc_fee_amount', function($amount) {
229-
if (function_exists('convert_to_current_currency')) {
230-
return convert_to_current_currency($amount);
249+
```php
250+
// Modify calculated fees for currency conversion
251+
add_filter( 'cfwc_calculated_single_fee', function( $fee, $rule, $total ) {
252+
if ( function_exists( 'convert_to_current_currency' ) ) {
253+
return convert_to_current_currency( $fee );
231254
}
232-
return $amount;
233-
});
255+
return $fee;
256+
}, 10, 3 );
234257
```
235258

236-
### With Shipping Plugins
259+
### With Third-Party Insurance Plugins
237260

238-
```
239-
// Combine with shipping calculations
240-
add_action('woocommerce_shipping_calculated', function() {
241-
// Recalculate customs based on shipping destination
242-
WC()->cart->calculate_fees();
243-
});
261+
```php
262+
// Integrate shipping insurance with CIF customs calculations
263+
add_filter( 'cfwc_insurance_value', function( $insurance_value, $product_value, $method ) {
264+
if ( function_exists( 'get_cart_insurance_amount' ) ) {
265+
$total_insurance = get_cart_insurance_amount();
266+
$cart_subtotal = WC()->cart->get_cart_contents_total();
267+
268+
if ( $cart_subtotal > 0 ) {
269+
return ( $product_value / $cart_subtotal ) * $total_insurance;
270+
}
271+
}
272+
return $insurance_value;
273+
}, 10, 3 );
244274
```
245275

246276
## Performance
@@ -314,6 +344,29 @@ GNU General Public License for more details.
314344

315345
## Changelog
316346

347+
### Version 1.1.4 - January 2026
348+
349+
**New Feature: CIF Customs Valuation**
350+
351+
- Added support for CIF (Cost, Insurance, Freight) customs valuation method.
352+
- New setting to choose between FOB (product value only) and CIF (product + shipping) calculation methods.
353+
- Shipping costs are proportionally distributed across products when CIF is enabled.
354+
- Added `cfwc_customs_value` filter to customize customs value calculations.
355+
- Added `cfwc_insurance_value` filter for third-party insurance plugin integration.
356+
- Added `cfwc_fee_label` filter to customize fee labels at checkout.
357+
- Added `cfwc_product_origin` filter to override product origin programmatically.
358+
359+
**Improvements**
360+
361+
- Made "Setup Status" notice on settings page dismissible.
362+
- Improved code quality with PHPCS and PHPStan compliance.
363+
364+
**Developer Notes**
365+
366+
- CIF is an opt-in feature; default behavior (FOB) remains unchanged.
367+
- Existing orders and rules are not affected.
368+
- Virtual/downloadable products are automatically excluded from CIF calculations.
369+
317370
### Version 1.1.3 - December 2025
318371

319372
- Added new setting to calculate customs fees on original price (before discounts).

assets/css/admin-improvements.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Customs Fees for WooCommerce - Admin UI Improvements
33
*
44
* @package CFWC
5-
* @since 1.2.0
5+
* @since 1.1.4
66
*/
77

88
/* Responsive layout for settings */

assets/css/frontend.css

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,31 +286,29 @@ ul.cfwc-fees-breakdown li:before,
286286

287287
/* Info box on order received page */
288288
.cfwc-order-info-box {
289-
background-color: #f7f7f7;
290-
border-left: 4px solid #0073aa;
291-
padding: 20px;
289+
background-color: #f8f9fa;
290+
border: 1px solid #e0e0e0;
291+
border-radius: 4px;
292+
padding: 15px 20px;
292293
margin: 30px 0;
293294
}
294295

295296
.cfwc-order-info-box h3 {
296-
margin: 0 0 10px;
297-
color: #0073aa;
298-
font-size: 18px;
297+
margin: 0 0 8px;
298+
color: #333;
299+
font-size: 14px;
300+
font-weight: 600;
299301
}
300302

301303
.cfwc-order-info-box p {
302-
margin: 0 0 10px;
304+
margin: 0;
303305
color: #666;
304306
}
305307

306-
.cfwc-order-info-box p:last-child {
307-
margin-bottom: 0;
308-
}
309-
310308
.cfwc-order-info-box .cfwc-disclaimer {
311-
color: #999;
312-
font-size: 12px;
313-
font-style: italic;
309+
color: #666;
310+
font-size: 13px;
311+
line-height: 1.5;
314312
}
315313

316314
/* Email breakdown list */

changelog.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
*** Customs Fees for WooCommerce Changelog ***
22

3+
2026-01-15 - version 1.1.4
4+
* Add - CIF (Cost, Insurance, Freight) customs valuation method support.
5+
* Add - New setting to choose between FOB (product value only) and CIF (product + shipping) calculation methods.
6+
* Add - Shipping costs are proportionally distributed across products when CIF is enabled.
7+
* Add - `cfwc_customs_value` filter to customize customs value calculations.
8+
* Add - `cfwc_insurance_value` filter for third-party insurance plugin integration.
9+
* Add - `cfwc_fee_label` filter to customize fee labels at checkout.
10+
* Add - `cfwc_product_origin` filter to override product origin programmatically.
11+
* Update - Made "Setup Status" notice on settings page dismissible.
12+
* Update - Improved code quality with PHPCS and PHPStan compliance.
13+
* Dev - CIF is an opt-in feature; default behavior (FOB) remains unchanged.
14+
315
2025-12-11 - version 1.1.3
416
* Added new setting to calculate customs fees on original price (before discounts).
517
* Useful for promotions where products are discounted but tariffs should still be based on full product value.

customs-fees-for-woocommerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Customs Fees for WooCommerce
44
* Plugin URI: https://woocommerce.com/products/customs-fees
55
* Description: Add customs and import fees to WooCommerce orders based on destination country and product origin.
6-
* Version: 1.1.3
6+
* Version: 1.1.4
77
* Author: WooCommerce
88
* Author URI: https://woocommerce.com
99
* License: GPL v2 or later
@@ -35,7 +35,7 @@
3535
}
3636

3737
// Define plugin constants.
38-
define( 'CFWC_VERSION', '1.1.3' );
38+
define( 'CFWC_VERSION', '1.1.4' );
3939
define( 'CFWC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
4040
define( 'CFWC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
4141
define( 'CFWC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

0 commit comments

Comments
 (0)