Support

Account

Home Forums ACF PRO Using Options Page values in functions.php Reply To: Using Options Page values in functions.php

  • I don’t know it this is something that will be fixed or not. As a general rule I don’t use any plugin functions for ACF until after the init action.

    First thing is that you need to get the value inside your function because the value of outside the function will have no effect on the value inside the function.

    Since you have to get the value in the function anyway I would change the code to something like this:

    
     
      function disable_ups_ground_by_state( $rates ) {
        $disabled_ground = get_field('ground_disable_for_states', 'option');
        if (!$disabled_ground) {
          return;
        }
        global $woocommerce;
        // you also need to test to see if it's an array
        // before convering it ot an array
        if (!is_array($disabled_ground)) {
          $disabled_ground = array($disabled_ground);
        }
        if( in_array( $woocommerce->customer->get_shipping_state(), $disabled_ground ) ) {
          unset($rates['ups:03']);
        }
        return $rates;
      }
      add_filter( 'woocommerce_package_rates', 'disable_ups_ground_by_state', 10 );