• Resolved davidacardona

    (@davidacardona)


    Hi, I wonder if it would be possible to disable the COD option for specific cities with your plugin.

    I have thought a way could be to create a shipping zone based on those cities. But i dont know a plugin that allows me to create standard shipping woocommerce zones with cities.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi davidacardona,

    The reason we didn’t created a restriction for the cities is because they are a free text field on checkout, so if you restrict a city name and the customer type it differently (typo,special characters) the restriction will be ignored.

    Please add this in your functions.php and adjust the cities.

    add_filter( 'wc_smart_cod_available', 'cod_restrict_cities' );
    
    function cod_restrict_cities( $is_cod_available ) {
    
    	$shipping_city = isset( $_POST[ 's_city' ] ) ? $_POST[ 's_city' ] : false;
    	// cities you want to exclude
    	$restricted_cities = array(
    		'London', 
    		'Rome', 
    		'Barcelona'
    	);
    	
    	if( in_array( $shipping_city, $restricted_cities ) ) {
    		$is_cod_available = false;
    	}
    	
    	return $is_cod_available;
    
    }

    Let me know if any issues.
    [ Signature moderated ]

    • This reply was modified 6 years, 5 months ago by Jan Dembowski.
    Thread Starter davidacardona

    (@davidacardona)

    Hi, Thanks a lot!!, it seems to work!. You were right about cities, before we had the cities and states in free text fields, but now we have both of them on selectable lists. But our COD provider doesnt deliver to all of them.

    ¡So this improvement is going to help us a lot!

    I suggest this to be added as an optional box in a next version.
    And another suggestion, is to add an image for payment option as in https://wordpress.org/plugins/woocommerce-cod-advanced/

    With both of these, your plugin would be perfect for many more countries (at least 80% of latinamerica)

    Thanks a lot.

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi davidacardona,

    We just released an update ( 1.4.5 ) which supports city restriction along with other features.
    Please check and let me know if any issues.

    We will include the image for payment option in the next version.

    If you liked the plugin, it will help us a lot if you rate it. 🙂

    [ Signature moderated ]

    • This reply was modified 6 years, 5 months ago by Jan Dembowski.
    Thread Starter davidacardona

    (@davidacardona)

    Hi Stratos, i just tested the update and it works, but it creates another problem.

    If i enter a city in the new city field, my checkout page hides the COD payments by default, until the user choose the location fields. And this is a problem because many users would think that the COD option is simply not available at first sight.

    Do you understand?

    By some reason, when i use the code that you gave me before, it doesnt behave like this. The COD shows as available by default, and dissapears when the user selects a no-COD city.

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi david,

    That’s strange, the code is pretty much the same.
    I tested it and it works as it should. The cod is available by default if the city field is empty ( before the customer types something ).
    Did you removed the code block I sent you from the functions.php?
    Are you sure no other restriction in our plugin is causing this?

    [ Signature moderated ]

    • This reply was modified 6 years, 5 months ago by Jan Dembowski.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Disable for specific cities’ is closed to new replies.