Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @chirag, you can put below code into your them functions.php:

    function postcode_cash_on_delivery( $available_gateways ) {
      global $woocommerce;
    
      //example: allow COD in United States (US) and certain postcodes
      $cod_country = 'US';
      $cod_postcodes = array("02115", "02116", "10001", "10002");
    
      if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == $cod_county && !in_array($woocommerce->customer->get_postcode(), $cod_postcodes)) {
        unset(  $available_gateways['cod'] );
      }
    
      return $available_gateways;
    }
    
    add_filter( 'woocommerce_available_payment_gateways', 'postcode_cash_on_delivery' );
    Thread Starter Chirag Vora

    (@chirag740)

    Thanks Terry that works.
    However, in my case I have more than 3000 postcodes that allow cash on delivery.
    When put into the array within functions.php, the checkout is becoming a bit slow.

    Is there any alternative to this approach?

    hi chirag vora,

    kidly guide me, where is specified function.php file. And where do i put these code in function.php

    Hi Friends,

    kidly guide me, where is specified function.php file. And where do i put these code in function.php

    Hi, after login to WordPress Admin, you can mouseover Appearance sidebar menu, then click ‘Editor’ link, then on your right sidebar, open functions.php file and put those at the end of file and before symbol ‘?>’.

    You can refer my tutorial here also.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Allow Cash on Delivery only in certain postcodes’ is closed to new replies.