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 );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.