WPprodigy / woocommerce-product-fees

Add additional fees at checkout based on products that are in the cart.
https://wordpress.org/plugins/woocommerce-product-fees/
Other
26 stars 19 forks source link

Limit fee to country #30

Closed kleinermann closed 6 years ago

kleinermann commented 7 years ago

It would be great to have an option to limit a fee to a certain country.

I was thinking of hiding the fee based on the IP address until the customer enters their address and then use the info supplied by the customer instead.

I was looking at WC_Geo_IP for doing this but can't get it to work (https://docs.woocommerce.com/wc-apidocs/class-WC_Geo_IP.html).

I'd be very grateful for any suggestions.

WPprodigy commented 6 years ago

You can see how WooCommerce tries to get the geolocated state/country here: https://github.com/woocommerce/woocommerce/blob/fd2c67683765df96dd71e0dbcb60d3e9063d6f20/includes/wc-core-functions.php#L1021

You can use this same method to attempt and get a location. Then conditionally add fees.

This isn't something that would fit into this extension very well though right now I'm afraid, so will require some custom work.